Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在cocos2d-x js中设置计时器 i=0; 而(setTimeout()的第二个参数应该是延迟,其中延迟以微秒为单位(600微秒=0.6秒)。_Javascript_Cocos2d X_Cocos2d Js - Fatal编程技术网

Javascript 在cocos2d-x js中设置计时器 i=0; 而(setTimeout()的第二个参数应该是延迟,其中延迟以微秒为单位(600微秒=0.6秒)。

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)

更改代码中的这两行

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) 
            {
                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);