00:00
00:00
Newgrounds Background Image Theme

SonicKoi just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

As:simple Countdown Timer

1,280 Views | 6 Replies
New Topic Respond to this Topic

As:simple Countdown Timer 2006-06-11 10:55:38


AS:Main

This tutorial will teach you how to create a simple countdown timer. This can be used to add time to games, much like the timers in arcade games. I dont know if im explaining this right, but i hope ive got something on here. All apologised if this has been done before, i havent seen it personally.

Now to get on with teh tutorial!

First, create a dynamic text box, and in the properties bar at teh bottom, there will be a boz with teh word Var in it. Write "time" without teh "s in that box.

After which, click on your frame and hit F9. This will open up an actions box. Inside that box put:

var time:Number = 30;

this sets the number of seconds you want it to count down from. the var is teh same var which you put in teh dynamic text box, standing for variable. You can read more about variables in AS:Variables by -Toast-.

Next insert this into the actions:

setInterval(function() {

this tells flash taht you are about to deal with time, or in thsi case regular intervals of a certain lengh. That lengh will be determined at teh end of the code. Thios also opens up the reast of teh code.

now add this:

time ? --time : _root.gotoAndStop();

This tells flash that every time that interval is met, the variable time will go down by one. After taht theer is a gotoAndStop function, in which a number can be put into teh brackets. The function can be changed to something different like a stopAllSounds; function or something.

after add this:

}, 1000);

this closes teh code, and tell flash what lengh of interval, in what i believe to be is milliseconds.

here is a preview of what the code makes:

timer

I hope this will help you in some way.


BBS Signature

Response to As:simple Countdown Timer 2006-06-11 11:00:06


very nice! good tutorial! keep it up!

Response to As:simple Countdown Timer 2006-06-11 11:02:17


AS:Timer by GuyWithHisComp ;)


BBS Signature

Response to As:simple Countdown Timer 2006-06-11 11:02:20


I find that with games, its better to just add 1/framerate to a variable each frame. That way if the game lags, the time lags too so you're no less advantaged.

Response to As:simple Countdown Timer 2006-06-11 11:06:15


At 6/11/06 11:02 AM, Cybex wrote: I find that with games, its better to just add 1/framerate to a variable each frame. That way if the game lags, the time lags too so you're no less advantaged.

im not amazingly advanced i guess...


BBS Signature

Response to As:simple Countdown Timer 2006-06-11 11:09:27


At 6/11/06 11:02 AM, Cybex wrote: I find that with games, its better to just add 1/framerate to a variable each frame. That way if the game lags, the time lags too so you're no less advantaged.

True - Intervals are much more cpu intensive. :P

Response to As:simple Countdown Timer 2006-08-27 20:02:44


I have a problem when I input setInterval(function() {.
What do I put down for function?