0

以下代码只是“挂断”我的游戏,我正在使用带有craftyjs..的 javascript。

var trigger_de_movement=true;
pl.animate('PlayerMovingLeft', 1, 1); //this function starts animation named PlayerMovingLeft for 1 frame and repeates 1 time..
while (trigger_de_movement) {/*if animation is not playing, type time and go out and stop the loop*/
    if (!pl.isPlaying('PlayerMovingLeft')) {//checks if animation is playing for pl(ayer)
        var d=new Date();
        putMessage(d.getSeconds()+"."+d.getMilliseconds()); //this function puts message
        trigger_de_movement=false; //to make while loop not run forever
    }
}
4

1 回答 1

0

问题是,

if(!pl.isPlaying('PlayerMovingLeft')) 

如果If statement失败,则循环将是无限的,因为变量trigger_de_movement始终为真,直到 if 语句变为真。如果为假,则循环是无限的。所以最好你改变你的while to If并检查发生了什么

于 2013-12-04T05:57:01.507 回答