-
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.
-
Designer, Programmer, Musician
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?
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
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?
-
Designer, Programmer, Musician
Yeah send me the fla please. It would be better if I see what i'm doing hehe!
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
Designer, Programmer, Musician
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
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
Designer, Programmer, Musician
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.
Last edited by angelhdz; 12-04-2012 at 09:44 AM.
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
Designer, Programmer, Musician
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") }
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
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!
-
Designer, Programmer, Musician
Originally Posted by Terrencing
I think is meaning
Code:
clearInterval(_root.countdownInterval);
You're right, i put the _root in the wrong place. Hehe.
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|