Javascript 在cocos2d-x js中设置计时器 i=0; 而(setTimeout()的第二个参数应该是延迟,其中延迟以微秒为单位(600微秒=0.6秒)。
更改代码中的这两行 1-您应该使用“新建”来创建新的精灵 2-在setTimeout中,应该有一个函数,该函数应该与“this”绑定以使用当前类的函数,否则它将抛出错误找不到废话Javascript 在cocos2d-x js中设置计时器 i=0; 而(setTimeout()的第二个参数应该是延迟,其中延迟以微秒为单位(600微秒=0.6秒)。,javascript,cocos2d-x,cocos2d-js,Javascript,Cocos2d X,Cocos2d Js,更改代码中的这两行 1-您应该使用“新建”来创建新的精灵 2-在setTimeout中,应该有一个函数,该函数应该与“this”绑定以使用当前类的函数,否则它将抛出错误找不到废话 i=0; while (i<10) { var objectLabel = cc.Sprite("res/rect.png", cc.rect(0, 0, 100, 100)); function getRandomInt(min, max)
i=0;
while (i<10)
{
var objectLabel = cc.Sprite("res/rect.png", cc.rect(0, 0, 100, 100));
function getRandomInt(min, max)
{
return Math.floor(Math.random() * (max - min + 1)) + min;
}
objectLabel.x = getRandomInt(50, size.width);
objectLabel.y = size.height-40;
setTimeout(this.addChild(objectLabel, 5), 500);
objectLabel.runAction(cc.spawn(cc.moveBy(0.8, cc.p(0, size.height*(-1)+210))));
i++;
}
不幸的是,它根本不起作用。在这个过程中,如果我只写这个.addChild(objectLabel,5),它的工作方式是相同的:(
var objectLabel = new cc.Sprite("res/rect.png", cc.rect(0, 0, 100, 100));
setTimeout(function(){this.addChild(objectLabel, 5)}.bind(this), 600);