Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

AS2 Game Timer

New Here ,
Jun 01, 2013 Jun 01, 2013

Hey, basically I'm having real trouble with the timer in my game;

I have a countdown timer with the code:

timer = 30;

countdown = function(){ timer--; if(timer==0){

clearInterval(countdownInterval);

          _root.gotoAndPlay("GameOver");

}

}

countdownInterval = setInterval(countdown,1000);

Now this counts down fine though doesn't get me to the correct frame when it runs it get to 0, just goes to a blank frame. I may also note that the timer is inside a vcam layer so that it follows the character at the same time. So how would I get the timer to go to the correct frame when finished? Also the more important point, I have some collectables in my game that when you hit them I want it to pause the timer for a select amount of time. This is on the main games' layer. Now I'm unsure of this code and could really do with some help knowing how to do it since I've tried loads of different pieces.

Help would be much appriecated

*Edit: also I'm using this code to pick up the collectables which seems to work well except for adding or pausing time on the timer:

onClipEvent(enterFrame){

          if(_root.char.hitTest(this)){

                    unloadMovie(this);

          }

}

TOPICS
ActionScript
5.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 01, 2013 Jun 01, 2013

if that code is causing the _root timeline to go to the wrong frame, it's because either _root isn't what you think it is or you have no single "GameOver" frame label on your _root timeline.  (use Movie Explorer to check your frame labels.)

to pause your timer, use:

clearInterval(countdowninterval);

to restart your timer, use:

countdownInterval = setInterval(countdown,1000);

Translate
Community Expert ,
Jun 01, 2013 Jun 01, 2013

if that code is causing the _root timeline to go to the wrong frame, it's because either _root isn't what you think it is or you have no single "GameOver" frame label on your _root timeline.  (use Movie Explorer to check your frame labels.)

to pause your timer, use:

clearInterval(countdowninterval);

to restart your timer, use:

countdownInterval = setInterval(countdown,1000);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 01, 2013 Jun 01, 2013

I've tried looking at my frame labels and they seem correct. When I take the _root from it the timer just stays at 0 and doesn't move to another frame. Also how would I use the:

clearInterval(countdowninterval);

on one of the collectables because I don't think I'm using the actionscript correctly it will pick up the collectable but the timer just carries on...

Thanks


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 01, 2013 Jun 01, 2013
LATEST

you just need to execute:

clearInterval(countdowninterval);

when you pick up an object.  you must have some kind of loop that probably checks a hittest between your character and the objects.  that's where you would add the clearInterval.

attach a screenshot showing your frame label (in the properties panel).

also, if you have more than one scene, make sure you're not testing scenes (test movie) when you test that goto/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 01, 2013 Jun 01, 2013

try it:

time=60;


Edit1=time;



function timer()


{


if(time>0)


{


time
+=-1;


Edit1=timer;


}


}


setInterval
(timer, 1000);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines