Reputation: 15
I have stocked on a problem with adding a time delay for an object. The main idea is that i want to change the level of the game to the next when the player hit a specific object. But i do not want this to happen immediately, so i want to add a delay of 3 sec.
onClipEvent(enterframe) {
if (_root.char.hitTest(this)) {
//add dealy for the next 2 lines.
unloadMovie(this);
_root.gotoAndStop("StageL2");
}
}
Upvotes: 0
Views: 51
Reputation: 327
I would add a counter, based upon your framerate (say you have 24fps, 3 seconds is 72frames):
var hit = false;
var counter;
onClipEvent(enterframe) {
if (_root.char.hitTest(this)) {
hit = true;
}
if(!hit) {
waitcounter = 0;
} else {
waitcounter++;
}
if(waitcounter >= 72) {
unloadMovie(this);
_root.gotoAndStop("StageL2");
}
}
I've also added an extra routine to make the hitTest trigger a variable, otherwise the hit should be true for 72 frames (and if you have moving objects, there's a really small chance that's true).
Don't forget to reset your variables when you go to the next stage.
Upvotes: 0