PDA

View Full Version : [AS2][F8] SIMPLE Timer


demoniaco
09-08-2008, 05:13 AM
Hey ^.^,
I'm trying to make a timer for my game, I got one in the code below if it's useful at all? I have my timer on 1 scene, then how do i get a second scene and have it say "You have taken *Timer* amount of seconds to complete this level. Well done!".
I need code to stop this timer and the code to import the seconds recorded into the next scene.


start_time = getTimer();

onEnterFrame = function () {

elapsed_time = getTimer()-start_time;

_root.count.text = time_to_string(elapsed_time);

_root.count_down.text = time_to_string(_root.countdown-elapsed_time);

};

function time_to_string(time_to_convert) {

elapsed_hours = Math.floor(time_to_convert/3600000);

remaining = time_to_convert-(elapsed_hours*3600000);

elapsed_minutes = Math.floor(remaining/60000);

remaining = remaining-(elapsed_minutes*60000);

elapsed_seconds = Math.floor(remaining/1000);

remaining = remaining-(elapsed_seconds*1000);

elapsed_fs = Math.floor(remaining/10);

if (elapsed_hours<10) {

hours = "0"+elapsed_hours.toString();

} else {

hours = elapsed_hours.toString();

}

if (elapsed_minutes<10) {

minutes = "0"+elapsed_minutes.toString();
} else {

minutes = elapsed_minutes.toString();
}

if (elapsed_seconds<10) {

seconds = "0"+elapsed_seconds.toString();

} else {

seconds = elapsed_seconds.toString();
}
if (elapsed_fs<10) {
hundredths = "0"+elapsed_fs.toString();
} else {
hundredths = elapsed_fs.toString();
}
return minutes+":"+seconds+":"+hundredths;
}

nikhiljoshi122
09-08-2008, 08:08 PM
Hey ^.^,
I'm trying to make a timer for my game, I got one in the code below if it's useful at all? I have my timer on 1 scene, then how do i get a second scene and have it say "You have taken *Timer* amount of seconds to complete this level. Well done!".
I need code to stop this timer and the code to import the seconds recorded into the next scene.


start_time = getTimer();

onEnterFrame = function () {

elapsed_time = getTimer()-start_time;

_root.count.text = time_to_string(elapsed_time);

_root.count_down.text = time_to_string(_root.countdown-elapsed_time);

};

function time_to_string(time_to_convert) {

elapsed_hours = Math.floor(time_to_convert/3600000);

remaining = time_to_convert-(elapsed_hours*3600000);

elapsed_minutes = Math.floor(remaining/60000);

remaining = remaining-(elapsed_minutes*60000);

elapsed_seconds = Math.floor(remaining/1000);

remaining = remaining-(elapsed_seconds*1000);

elapsed_fs = Math.floor(remaining/10);

if (elapsed_hours<10) {

hours = "0"+elapsed_hours.toString();

} else {

hours = elapsed_hours.toString();

}

if (elapsed_minutes<10) {

minutes = "0"+elapsed_minutes.toString();
} else {

minutes = elapsed_minutes.toString();
}

if (elapsed_seconds<10) {

seconds = "0"+elapsed_seconds.toString();

} else {

seconds = elapsed_seconds.toString();
}
if (elapsed_fs<10) {
hundredths = "0"+elapsed_fs.toString();
} else {
hundredths = elapsed_fs.toString();
}
return minutes+":"+seconds+":"+hundredths;
}


just get ur final time fr the first scene assign it a global variable n thn go to ny scene u want u can easily fetch yor value
enjoy>>>

yogsmca
12-05-2008, 04:33 PM
Hi got some problem with timer


The timer should start AFTER the player starts playing.But her starts after loading...

i had uploaded my fla file over here:
http://dhayalan.com/bubble.rar

Can u plz help me even i can pay u .. get me ur messegger id .....

regards
yogs

asf8
12-05-2008, 05:33 PM
Hi got some problem with timer The timer should start AFTER the player starts playing.But her starts after loading... Can u plz help me even i can pay u .. get me ur messegger id ..... regards yogs


@ yogsmca, what was wrong with your previous thread about timers?

flash game timer
http://www.actionscript.org/forums/showthread.php3?t=190236

yogsmca
12-12-2008, 05:41 PM
I had done the changes and tried but i was unable to start the game "start button not working"

Button instance name = yourButton_mc
Textfield instance name = outPutText_txt

regards
yogs