Be a Supporter!

As : Easy Time Counter for a game.

  • 5,492 Views
  • 26 Replies
New Topic Respond to this Topic
Phasez
Phasez
  • Member since: Feb. 20, 2005
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
As : Easy Time Counter for a game. Jan. 12th, 2006 @ 08:30 PM Reply

/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

Phasez
Phasez
  • Member since: Feb. 20, 2005
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to As : Easy Time Counter for a game. Jan. 12th, 2006 @ 08:33 PM Reply

Lol on Sec dinamic text box properties put on var Secs not sec

Phasez
Phasez
  • Member since: Feb. 20, 2005
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to As : Easy Time Counter for a game. Jan. 12th, 2006 @ 08:42 PM Reply

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

Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to As : Easy Time Counter for a game. Jan. 12th, 2006 @ 09:29 PM Reply

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
}

Phasez
Phasez
  • Member since: Feb. 20, 2005
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to As : Easy Time Counter for a game. Jan. 12th, 2006 @ 09:32 PM Reply

Thanks Glaiel hehe

Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to As : Easy Time Counter for a game. Jan. 12th, 2006 @ 09:36 PM Reply

At 1/12/06 09:29 PM, Glaiel_Gamer wrote: secs = Math.round(atime)

I MEAN secs=Math.round(atime/fps)

Phasez
Phasez
  • Member since: Feb. 20, 2005
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to As : Easy Time Counter for a game. Jan. 12th, 2006 @ 09:39 PM Reply

Glaiel Can u explain me the ? conditional operator?

Vengeance
Vengeance
  • Member since: Mar. 18, 2005
  • Offline.
Forum Stats
Member
Level 28
Blank Slate
Response to As : Easy Time Counter for a game. Jan. 13th, 2006 @ 12:18 AM Reply

At 1/12/06 09:29 PM, Glaiel_Gamer wrote: blah

hahahaha, phazes got pwned.
hahaha rofl!!!!11!1!!!one!!!eleven111!!!1


========|| WWWWWWWW>[-[Blog] - [Audio] - [Userpage] - [Flash] - [Last.fm]-]<WWWWWWWW ||========

BBS Signature
authorblues
authorblues
  • Member since: Jun. 21, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to As : Easy Time Counter for a game. Jan. 13th, 2006 @ 12:23 AM Reply

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);


BBS Signature
Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to As : Easy Time Counter for a game. Jan. 13th, 2006 @ 05:27 AM Reply

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 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);

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.


- - Flash - Music - Images - -

BBS Signature
Chaz
Chaz
  • Member since: Sep. 27, 2005
  • Offline.
Forum Stats
Member
Level 23
Game Developer
Response to As : Easy Time Counter for a game. Jan. 13th, 2006 @ 06:18 AM Reply

At 1/13/06 05:27 AM, Denvish wrote: stuff

That really makes sense D.


BBS Signature
Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to As : Easy Time Counter for a game. Jan. 13th, 2006 @ 06:33 AM Reply

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.

T-H
T-H
  • Member since: Jan. 7, 2004
  • Offline.
Forum Stats
Member
Level 40
Blank Slate
Response to As : Easy Time Counter for a game. Jan. 13th, 2006 @ 06:40 AM Reply

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 disadvantage
The 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...

authorblues
authorblues
  • Member since: Jun. 21, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to As : Easy Time Counter for a game. Jan. 13th, 2006 @ 10:08 AM Reply

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);


BBS Signature
Rantzien
Rantzien
  • Member since: Jan. 27, 2005
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to As : Easy Time Counter for a game. Jan. 13th, 2006 @ 10:38 AM Reply

At 1/13/06 10:08 AM, authorblues wrote: secs--;

I don't like that line of code...


BBS Signature
Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to As : Easy Time Counter for a game. Jan. 13th, 2006 @ 10:39 AM Reply

authorblues, I suggest a setTimeout instead of keeping a "secs" variable

authorblues
authorblues
  • Member since: Jun. 21, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to As : Easy Time Counter for a game. Jan. 13th, 2006 @ 10:42 AM Reply

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.


BBS Signature
Lord-Sonx
Lord-Sonx
  • Member since: Jan. 17, 2004
  • Offline.
Forum Stats
Member
Level 32
Blank Slate
Response to As : Easy Time Counter for a game. Jan. 13th, 2006 @ 10:42 AM Reply

erm, isin't there somehting exactly like this that comes with flash?

not suggesting you stole the code fomr there, just making a point..

Gbanger
Gbanger
  • Member since: Jan. 29, 2006
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to As : Easy Time Counter for a game. Feb. 3rd, 2006 @ 11:14 PM Reply

is it just me or does that code not actually work it does seconds finee but my minutes one goes crazy

Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to As : Easy Time Counter for a game. Feb. 19th, 2006 @ 12:26 PM Reply

what if your PC lags and fps goes down?


- Matt, Rustyarcade.com

Cybex
Cybex
  • Member since: Mar. 4, 2005
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to As : Easy Time Counter for a game. Feb. 19th, 2006 @ 12:41 PM Reply

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.

Newsdee
Newsdee
  • Member since: Jan. 21, 2005
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to As : Easy Time Counter for a game. Feb. 19th, 2006 @ 12:46 PM Reply

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.

La-Chupa-Thingy
La-Chupa-Thingy
  • Member since: Apr. 16, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to As : Easy Time Counter for a game. May. 29th, 2006 @ 02:29 AM Reply

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)?

zac13x4
zac13x4
  • Member since: May. 29, 2006
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to As : Easy Time Counter for a game. Aug. 19th, 2006 @ 11:17 PM Reply

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

xWELSHxDRAGONx
xWELSHxDRAGONx
  • Member since: Apr. 13, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to As : Easy Time Counter for a game. Aug. 20th, 2006 @ 04:37 PM Reply

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

xWELSHxDRAGONx
xWELSHxDRAGONx
  • Member since: Apr. 13, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to As : Easy Time Counter for a game. Aug. 20th, 2006 @ 04:41 PM Reply

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?

Depredation
Depredation
  • Member since: Sep. 5, 2005
  • Offline.
Forum Stats
Member
Level 17
Game Developer
Response to As : Easy Time Counter for a game. Aug. 20th, 2006 @ 05:14 PM Reply

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.

BBS Signature