| Home | Tutorials | Forums | Articles | Blogs | Movies | Library | Employment | Press | Buy templates |
|
|
#1 |
|
Love you long time
Join Date: May 2001
Location: Sydney, Australia
Posts: 299
|
I am building a small game that requires a timer.
So far I have a movie clip, instance name of "timer", and within this movie clip is a dynamic text box with a variable name of "newTime". I have placed the clip on the stage and this is the code given to it : onClipEvent (load) { startTime = getTimer(); } onClipEvent (enterFrame) { currentTime = getTimer(); newTime = 60 - int((currentTime - startTime) / 1000) ; } This works fine as a timer counting backwards from 60. The problem I am having is stopping the timer at 0. Does anyone have any answers for what I am trying to achieve ?. Thanks for your time. |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Nov 2000
Location: Australia
Posts: 8,612
|
Code:
if (newTime != 0) {
currentTime = getTimer();
newTime = 60-int((currentTime-startTime)/1000);
} else {
// some action
}
__________________
Cheers Jesse Stratford ActionScript.org Cofounder Email: presented in this way to stop spam-bots: My email is composed of my first name (jesse) followed by my last name (stratford) followed by @ followed by actionscript.org Please don't email or PM me Flash questions, that's what the Forums are for! ![]() Please don't rely on me reading my PMs either. Email me about important stuff. |
|
|
|
|
|
|
|
|
#3 |
|
Love you long time
Join Date: May 2001
Location: Sydney, Australia
Posts: 299
|
Thanks Jesse
|
|
|
|
|
|
#4 |
|
Citrus Fresh
Join Date: Sep 2001
Location: Mnpls, MN, USA
Posts: 11
|
With this code, what would be the most efficient way to display a 0 before any number less than 10?
|
|
|
|
|
|
#5 |
|
Administrator
Join Date: Nov 2000
Location: Australia
Posts: 8,612
|
ahh:
Code:
if (newTime<=10) {
newTime = 0;
} else if (newTime != 0) {
currentTime = getTimer();
newTime = 60-int((currentTime-startTime)/1000);
} else {
// some action
}
__________________
Cheers Jesse Stratford ActionScript.org Cofounder Email: presented in this way to stop spam-bots: My email is composed of my first name (jesse) followed by my last name (stratford) followed by @ followed by actionscript.org Please don't email or PM me Flash questions, that's what the Forums are for! ![]() Please don't rely on me reading my PMs either. Email me about important stuff. |
|
|
|
|
|
#6 |
|
Registered User
Join Date: Feb 2001
Location: cincinnati
Posts: 45
|
I tried to start this code with a key press and it just stopped the displaying the count-down. It showed the number on the key press... not quite what I had in mind.
I want to start the timer on my keypress and have it count down from 60. thanks for any help you can give. |
|
|
|
|
|
#7 |
|
Administrator
Join Date: Nov 2000
Location: Australia
Posts: 8,612
|
Pop this on an MC:
Code:
onClipEvent (keyDown) {
go = true;
startTime = getTimer();
}
onClipEvent (enterFrame) {
if (go) {
if (newTime != 0) {
currentTime = getTimer();
newTime = 60-int((currentTime-startTime)/1000);
} else {
// some action
}
}
}
__________________
Cheers Jesse Stratford ActionScript.org Cofounder Email: presented in this way to stop spam-bots: My email is composed of my first name (jesse) followed by my last name (stratford) followed by @ followed by actionscript.org Please don't email or PM me Flash questions, that's what the Forums are for! ![]() Please don't rely on me reading my PMs either. Email me about important stuff. |
|
|
|
|
|
#8 |
|
Registered User
Join Date: Feb 2001
Location: cincinnati
Posts: 45
|
Thanks for you help!
|
|
|
|
|
|
#9 |
|
Citrus Fresh
Join Date: Sep 2001
Location: Mnpls, MN, USA
Posts: 11
|
I'm using this code for a game timer... I'd like to pause it when the help button (on the main stage) is pressed. What would be the best way to accomplish this?
|
|
|
|
|
|
#10 |
|
Administrator
Join Date: Nov 2000
Location: Australia
Posts: 8,612
|
you'd have to disable the countdown timer thingo, time how long the help screen was up for, then add it to the time limit and continue the timer... or note the number of elapsed seconds each time the help screen is disaplayed, disable the timer, and when you restart the time, subtract that number of seconds from the original time limit... that's prolly easiest.
__________________
Cheers Jesse Stratford ActionScript.org Cofounder Email: presented in this way to stop spam-bots: My email is composed of my first name (jesse) followed by my last name (stratford) followed by @ followed by actionscript.org Please don't email or PM me Flash questions, that's what the Forums are for! ![]() Please don't rely on me reading my PMs either. Email me about important stuff. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Creating a Game Timer | LocoDave | ActionScript 1.0 (and below) | 2 | 10-05-2004 01:17 PM |
| how to add timer for drag & drop game.. | booniraj | Gaming and Game Development | 3 | 10-15-2003 05:43 AM |
| Game Timer | amcquade | Gaming and Game Development | 2 | 07-07-2003 06:59 PM |
| Another Game Timer question (MX) | friz2002 | Gaming and Game Development | 13 | 04-17-2003 01:47 AM |
| Building a game timer?... | tr394 | Gaming and Game Development | 3 | 11-19-2002 07:45 PM |