Skip to main content
Participating Frequently
March 3, 2013
Question

Convert a frame-timer into a MS-timer

  • March 3, 2013
  • 2 replies
  • 703 views

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!

This topic has been closed for replies.

2 replies

Inspiring
March 3, 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?

Ned Murphy
Legend
March 3, 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.

Participating Frequently
March 3, 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.

Ned Murphy
Legend
March 3, 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.