我已经存在为对象添加时间延迟的问题。 主要思想是当玩家击中特定物体时,我想将游戏等级更改为下一个。但我不希望这种情况立即发生,所以我想加上3秒的延迟。
onClipEvent(enterframe) {
if (_root.char.hitTest(this)) {
//add dealy for the next 2 lines.
unloadMovie(this);
_root.gotoAndStop("StageL2");
}
}
答案 0 :(得分:1)
您可以使用Timer
来完成此操作像这样:
var myInterval:Number;
function myMethode():Void
{
trace("Executed myMethode() after 3 Seconds")
clearInterval(myInterval);
}
myInterval = setInterval(this, "myMethode", 3000);
答案 1 :(得分:0)
我会根据你的帧率添加一个计数器(假设你有24fps,3秒是72帧):
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");
}
}
我还添加了一个额外的例程来使hitTest触发器成为一个变量,否则命中应该为72帧(如果你有移动的物体,那么'真的)。
在进入下一阶段时,不要忘记重置变量。