-
How do i do this timer?
Code:
_root.timer1 = 200;
countdown = function ()
{
_root.timer1--;
if (_root.timer1 == 0){
clearInterval(countdownInterval);
}
}
stop();
countdownInterval = setInterval(countdown, 250);
I'm on "stage1" and die, then i goto "gameover" stage and press the replay button. (it's a game)
And now this code above is being executed 2 times, it goes twice as fast as i should do. Any help here?
Sorry, I'm new and trying to learn. :confused:
-
It works fine on my side. I used "traces" to test your script. The timer start to increase until 0, then it stops and executes the code above the clearInterval.
I think you issue has to do with your .fla, some movieclip, some frame, some other code...
What it's supposed to happen before, while and after the timer?
-
When i complete the level 1 map, another script takes the time and print it in the end screen ( not the "gameover" screen). That works fine.
But if I die, I go back to the "info screen" and press ready. Then I goto Level 1 and the timer go twice as fast.
You can find the game at my website here
Want to have the .fla file?
-
Yeah send me the fla please. It would be better if I see what i'm doing hehe!
-
Ok! I think i know where is the issue. Your game at your site helped me have a clear vision of the situation. Let me work on it :)
-
In the script when you die that then you are redirected to the "play again" frame, put this:
PHP Code:
_root.clearInterval(countdownInterval);
That fix your problem my friend :)
Explanation: The countdownInterval will only be cleared when the timer reaches 0. When you die, the timer will keep counting...so each time you replay the game, the timer multiplies its speed. You need to clear the interval when dying. (Dying is the script where it detects when the characters runs out of HP/lifes, or when it falls down)
Or if you have a lot of ways for the character to die, then put the clearInterval script on the "play again" frame.
-
But it's better that you ckeck all your dying ways in one if statement, Eg:
PHP Code:
//if my character falls down, OR if my character's HP/life is iqual to 0, OR if my character hit the BIG BOSS,
if(myCharacter._y>Stage.height || myCharacter.HP==0 || myCharacter.hitTest(_root.BigBoss)){
//then go to and stop try again frame and clear the timer interval
_root.clearInterval(countdownInterval);
gotoAndStop("try again frame")
}
-
I think is meaning
Code:
clearInterval(_root.countdownInterval);
-
Thank you! It worked.
It's my first "game" in flash and it's not so organized. I don't think I can put all the "dying ways" in one if statment. But I will keep that in mind when i work on the new, more organized one. This one was just for practices.
Thanks again!:)
-
Quote:
Originally Posted by
Terrencing
I think is meaning
Code:
clearInterval(_root.countdownInterval);
You're right, i put the _root in the wrong place. Hehe.