Ultimate Gear War
Join the alien war, prepare your gear and protect your base at all cost!
4.13 / 5.00 17,528 Views/As:MainAs:Main
Hi, we are going to make a time counter for a game.
http://img70.imagesh..e=timecounter8dt.swf
1.- Make 2 Dinamic Text Box. Minutes & Seconds.
In the Dinamic Text properties on Minutes ,
where it say var put mins & on seconds put sec.
2. Open on your first frame Actions Panel.
3. We are going to put some variables after the function
4. Now we are going to make a function called time_
fps = 30; //put here the fps number if you have 12 put 12 if you have 50 put 50.
min = 3; //or whatever you want but less than 59
sec = 59; // or whatever you want but less than 59
//We create a function that is going to be called soon.
function time_()
{
if(fps > 0) // we are checking if the fps is greater than 0
{
fps--; //we decrease it by one.
}else // if fps is not greater than 0 then do the next action
{
sec++; // we increase the seconds by one,if you want to decrease it put sec--
fps = 30; // we put again our fps
}
//Now we are going to change the minutes
if(sec >= 60) // we check if sec its greater than 60 why 60 it is going to look better/
{
min++;
sec = 0; // just look at a clock and you will see why it changes to cero.
}
//if you want to decrease your mins just put this bit of code
if(sec <= -1) // why -1 becouse if we put 0 is going to look strange
{
min--;
sec = 59; // you know why
}
}
Now we are going to Make a
onEnterFrame = function()
{
time_(); // we call the function like this. if it is on a mc or something else put _level0.time_(); or _root.time();
_root.Mins = min;
//when the secs are < 9 it will look like this 3:9 and we want to add a cero on 3:09
if(sec <= 9 && sec >= 0)
{
_root.Secs = "0"+ sec;
}else //if its not 1 digit number ^^
{
_root.Secs = sec;
}
/ /now if minutes are 0 and sec 0 then do whatever you want so we want to stop it there
if(sec <= 0 && min <= 0)
{
sec=0;
min = 0;
do whatever you want
nextFrame();
gotoAndStop("lose");
etc.
}
}
Thanks you , this is my first tutorial. And i just want to say if you dont understand my english its becouse im mexican and im really bad on English. & I dont miss one thing.. the completed code.
Remember the two dinamic text box.
//////////////////////////////////////////
/////////////////////
fps = 30;
min = 3;
sec = 59;
function time_()
{
if(fps > 0)
{
fps--;
}else
{
sec--;
fps = 30;
}
if(sec >= 60)
{
min++;
sec = 0;
}
if(sec <= -1)
{
min--;
sec = 59;
}
}
onEnterFrame = function()
{
time_();
_root.Mins = min;
if(sec <= 9 && sec >= 0)
{
_root.Secs = "0"+ sec;
}else
{
_root.Secs = sec;
}
if(sec <= 0 && min <= 0)
{
sec=0;
min = 0;
}
}
Time Counter Example ^^ You are free to compress it. TimeCounter Example ^^ you can descompress it if you want
Lol on Sec dinamic text box properties put on var Secs not sec
Lol and on Mins dinamic text box var its Mins not min . So dont make a mistake , thanks. and sry for the triple post.l ol
Man your code is crazy! Here's a much better version (untested, there will be errors)
fps=30
secs=240
atime=fps*secs
onEnterFrame=function(){
atime -= 1
secs = Math.round(atime)
Mins = secs%60
Secs = secs-Mins*60
Secs<10?Secs="0"+Secs:null
}
At 1/12/06 09:29 PM, Glaiel_Gamer wrote: secs = Math.round(atime)
I MEAN secs=Math.round(atime/fps)
Glaiel Can u explain me the ? conditional operator?
At 1/12/06 09:29 PM, Glaiel_Gamer wrote: blah
hahahaha, phazes got pwned.
hahaha rofl!!!!11!1!!!one!!!eleven111!!!1
At 1/12/06 09:29 PM, Glaiel_Gamer wrote: Man your code is crazy! Here's a much better version
a step further maybe?
var secs:Number = 240;
var dispS:Number, dispM:Number;
var time:Number = setInterval(function(){
secs--;
dispM = Math.floor(secs/60);
var tempS:Number = secs%60;
dispS = (tempS<10?"0":"")+tempS;
}, 1000);
At 1/13/06 12:23 AM, authorblues wrote:At 1/12/06 09:29 PM, Glaiel_Gamer wrote: Man your code is crazy! Here's a much better versiona step further maybe?
var secs:Number = 240;
var dispS:Number, dispM:Number;
var time:Number = setInterval(function(){
secs--;
dispM = Math.floor(secs/60);
var tempS:Number = secs%60;
dispS = (tempS<10?"0":"")+tempS;
}, 1000);
Yeah. setInterval is definitely the way to go if you want an accurate time counter. However, people with slower computers might be at a disadvantage if you did this, because their game may run at a slower FPS than a quicker PC, and therefore they could get less done in the allotted time. In which case a counter based onEnterFrame would be fairer.
At 1/13/06 05:27 AM, Denvish wrote: stuff
That really makes sense D.
At 1/13/06 05:27 AM, Denvish wrote: Yeah. setInterval is definitely the way to go if you want an accurate time counter. However, people with slower computers might be at a disadvantage
The reason i never use set interval.
At 1/13/06 06:33 AM, Glaiel_Gamer wrote:At 1/13/06 05:27 AM, Denvish wrote: Yeah. setInterval is definitely the way to go if you want an accurate time counter. However, people with slower computers might be at a disadvantageThe reason i never use set interval.
barely ever noticable, unless you use an absolute load of them at a time and/or other complexities . Admittable though there are very few faults with onEnterFrame timers, as they will put far less strain on the movie, so yeah I guess...
At 1/13/06 12:23 AM, authorblues wrote: a step further maybe?
well, personally, im appauled that no one even tore me a new one for messing up my code. its that damn datatyping. its ruining my reputation...
var secs:Number = 240;
var dispS:String, dispM:String;
var time:Number = setInterval(function(){
secs--;
dispM = Math.floor(secs/60);
var tempS:Number = secs%60;
dispS = (tempS<10?"0":"")+tempS;
}, 1000);
At 1/13/06 10:08 AM, authorblues wrote: secs--;
I don't like that line of code...
authorblues, I suggest a setTimeout instead of keeping a "secs" variable
At 1/13/06 10:38 AM, Rantzien wrote: I don't like that line of code...
you seemed to like it better last night...
At 1/13/06 10:39 AM, Inglor wrote: authorblues, I suggest a setTimeout instead of keeping a "secs" variable
how will having to create a new timeout every second going to keep me from needing a "sec" variable? i can understand using it as a timer, but you couldnt use it to display the information dynamically.
erm, isin't there somehting exactly like this that comes with flash?
not suggesting you stole the code fomr there, just making a point..
is it just me or does that code not actually work it does seconds finee but my minutes one goes crazy
what if your PC lags and fps goes down?
- Matt, Rustyarcade.com
At 2/19/06 12:26 PM, MattShaile wrote: what if your PC lags and fps goes down?
Then the timer will also go slower which would be good in a game so people with bad computers dont have a disadvantage. That points already been covered.
You could also use getTimer(), and then act based on the time elapsed.
This makes everything fps-independent (no problems with slow PCs), but is harder to handle.
I'm trying to make just a plain Countdown timer from 35 minutes. can someone explain Step-by-step (including where to put each set of action script)?
can someone rewrite that acion script but change so that it can count down days as well. and of course give me the variables and stuff. thanx
HOLY SHIT
startTime = 60*60;//secs
onEnterFrame = function () {
time = Math.floor(Math.round(startTime-(getTimer(
)/1000))/3600)%60+":"+Math.floor(Math.roun
d(startTime-(getTimer()/1000))/60)%60+":"+
Math.round(startTime-(getTimer()/1000))%60
;
};
:P
sorry didnt realise you awnted days aswell
startTime = 60*60*30;
onEnterFrame = function () {
time = Math.floor(Math.round(startTime-(getTimer(
)/1000))/86400)%24+":"+Math.floor(Math.rou
nd(startTime-(getTimer()/1000))/3600)%24+"
:"+Math.floor(Math.round(startTime-(getTim
er()/1000))/60)%60+":"+Math.round(startTim
e-(getTimer()/1000))%60;
trace(time);
};
if you need months just ask. Years?
At 8/19/06 11:17 PM, zac13x4 wrote: can someone rewrite that acion script but change so that it can count down days as well. and of course give me the variables and stuff. thanx
Great you bumped an 3 month old topic. Why not make a new one on the BBS?
Don't bump old topics of luis will ban yo ass.