cocos2d-js callFunc 전참

11351 단어 Cocos2d-x3.xCocos2d-JS
1. 매개 변수를 전달합니다.
pg.TestScene.prototype.init = function () {
    if (cc.Scene.prototype.init.call(this)) {

        var sprite = cc.Sprite.create(res.Bet_HighLighted_png);
        sprite.setPosition(cc.p(cc.winSize.width/2, cc.winSize.height/2));
        this.addChild(sprite, 1, 100);

        var moveToSeat = cc.moveTo(0.5, cc.p(200, 200));
        var rotateBy = cc.rotateBy(0.5, 180);
        var spawn = cc.spawn(moveToSeat, rotateBy);
        var delayTime = cc.delayTime(2);

        //  
        var callFunc = cc.callFunc(function () {
            console.log("1.sprite tag ==>" + sprite.getTag());
        }, this);
        //  
        // var callFunc = cc.callFunc(this.printLog, this, sprite);
        var sequence = cc.sequence(spawn, delayTime, callFunc);
        sprite.runAction(sequence);
        return true;
    }
    return false;
};

pg.TestScene.prototype.printLog = function (sprite) {
    console.log("2.sprite tag ==>" + sprite.getTag());
};


2. 두 개의 매개 변수를 전달합니다.
pg.TestScene.prototype.init = function () {
    if (cc.Scene.prototype.init.call(this)) {
       
        var sprite = cc.Sprite.create(res.Bet_HighLighted_png);
        sprite.setPosition(cc.p(cc.winSize.width / 2, cc.winSize.height / 2));
        this.addChild(sprite, 1, 100);

        var moveToSeat = cc.moveTo(0.5, cc.p(200, 200));
        var rotateBy = cc.rotateBy(0.5, 180);
        var spawn = cc.spawn(moveToSeat, rotateBy);
        var delayTime = cc.delayTime(2);
        
        var i = 0;
        var callFunc = cc.callFunc(this.printLog, this, [i , sprite]);
        var sequence = cc.sequence(spawn, delayTime, callFunc);
        sprite.runAction(sequence);
        return true;
    }
    return false;
};

pg.TestScene.prototype.printLog = function (target, data) {
    console.log("i ==>" + data[0]);
    console.log("sprite tag ==>" + data[1].getTag());
};

사용 방법:
cc.callFunc(function(target, data) {
        //target   action Node,Sprite 
        //data  , [data1, data2]  Array 

    },
    this, // HelloWorldLayer  ,  ,  removeChild

    data // , 
);

좋은 웹페이지 즐겨찾기