Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rate Thread Display Modes
Old 09-10-2001, 05:17 AM   #1
Reflex
Love you long time
 
Join Date: May 2001
Location: Sydney, Australia
Posts: 299
Question

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.
Reflex is offline   Reply With Quote
Old 09-10-2001, 06:17 AM   #2
Jesse
Administrator
 
Jesse's Avatar
 
Join Date: Nov 2000
Location: Australia
Posts: 8,612
Default

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.
Jesse is offline   Reply With Quote
Old 09-10-2001, 06:27 AM   #3
Reflex
Love you long time
 
Join Date: May 2001
Location: Sydney, Australia
Posts: 299
Default

Thanks Jesse
Reflex is offline   Reply With Quote
Old 09-12-2001, 08:29 PM   #4
Eric Neely
Citrus Fresh
 
Join Date: Sep 2001
Location: Mnpls, MN, USA
Posts: 11
Default

With this code, what would be the most efficient way to display a 0 before any number less than 10?
Eric Neely is offline   Reply With Quote
Old 09-13-2001, 03:32 AM   #5
Jesse
Administrator
 
Jesse's Avatar
 
Join Date: Nov 2000
Location: Australia
Posts: 8,612
Default

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.
Jesse is offline   Reply With Quote
Old 09-26-2001, 08:38 PM   #6
cinciem
Registered User
 
Join Date: Feb 2001
Location: cincinnati
Posts: 45
Default start with a keypress.

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.
cinciem is offline   Reply With Quote
Old 10-02-2001, 09:30 AM   #7
Jesse
Administrator
 
Jesse's Avatar
 
Join Date: Nov 2000
Location: Australia
Posts: 8,612
Default

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
		}
	}
}
It will start counting down when any key is pressed.
__________________
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.
Jesse is offline   Reply With Quote
Old 10-02-2001, 01:56 PM   #8
cinciem
Registered User
 
Join Date: Feb 2001
Location: cincinnati
Posts: 45
Smile Got it

Thanks for you help!
cinciem is offline   Reply With Quote
Old 12-03-2001, 04:42 PM   #9
Eric Neely
Citrus Fresh
 
Join Date: Sep 2001
Location: Mnpls, MN, USA
Posts: 11
Default

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?
Eric Neely is offline   Reply With Quote
Old 12-04-2001, 03:13 AM   #10
Jesse
Administrator
 
Jesse's Avatar
 
Join Date: Nov 2000
Location: Australia
Posts: 8,612
Default

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.
Jesse is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT. The time now is 11:45 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.