Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Convert a frame-timer into a MS-timer

New Here ,
Mar 03, 2013 Mar 03, 2013

Hi guys, im currently working on a shooting-game and something has been bugging my mind for the last hour or so. Im not very skilled with AS3 so please be patient with me.

Ok, so the problem I'm currently having, is that i have a timer which counts frames, which i want to turn into a millisecond timer.

The situation is that it is a timer which is supposed to work as a "break" between every time you can fire a shot.
I have the following code;

Makes the timer:

//how much time before allowed to shoot again

var cTime:int = 0;

//the time it has to reach in order to be allowed to shoot (in frames)

var cLimit:int = 12;

//whether or not the user is allowed to shoot

var shootAllow:Boolean = true;

//checking if cTime has reached the limit yet

if(cTime < cLimit){

    cTime ++;

} else {

    //if it has, then allow the user to shoot

    shootAllow = true;

    //and reset cTime

    cTime = 0;

}

    }

}

---------

So, i was wondering if anyone could "convert" it into so that instead of if having to reach 12 frames, it will allow the player to shoot every 0.5 second (So that it resets and make its able to shoot again after 0,5 seconds).

Any help or feedback is muchly appriciated. Thanks guys!

TOPICS
ActionScript
649
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 03, 2013 Mar 03, 2013

Look at yusing the Timer class.  If you need help seeing how to use it, search Google for a tutorial using terms like "AS3 Timer tutorial"

Each time you fire you need to set a disabler for shooting again and start a timer that resets that disabler after the timeout period passes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 03, 2013 Mar 03, 2013

Thanks for another quick reply, Ned.

I've looked into google, but the examples and problems other seem to have doesent help me or educate me about that way to use the Timer class.

Is it possible that you could mash down the code, or if you could share any good resource which explains the timer class well that you know of?

Thank you, again.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 03, 2013 Mar 03, 2013

I just did the Google search I suggested you do and found plenty of tutorials made to teach you how to use the Timer class.  If none of them are able to help you, it is doubtful anyone here will be able to either, short of doing the programming for you.  If you wait around you might find someone who is willing to.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 03, 2013 Mar 03, 2013
LATEST

Thanks again. After a couple of hours i managed to solve it in another way. I misunderstood AS's boundaries, once i read up on it i found a much better solution.


Thanks again for the willing to help to both you and Andrei1.


- Scott.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 03, 2013 Mar 03, 2013

What is the correlation between frames and shooting behavior? What is the significance of frame 12?

Also, it is not clear how you manage acts of shooting. I mean, how do you invoke it and how you disable it?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines