【问题标题】:cocos2d, can we call a function in "sequence" on a sprite?cocos2d,我们可以在精灵的“序列”中调用函数吗?
【发布时间】:2020-10-25 16:06:48
【问题描述】:

首先我将精灵从 a 移动到 b。当它到达 b 时,我需要调用一个函数来处理 sprite,即淡入淡出、更改图像等。我目前正在使用“序列”进行操作。

var seq_action = cc.Sequence.create(move_action, this.check_basket_under());

但它给了我这个错误 -

CCActionInterval.js:507 Uncaught TypeError: Cannot read property '_timesForRepeat' of undefined
    at Function.cc.sequence [as create] (CCActionInterval.js:507)
    at Class.sprite_create (app.js:110)
    at Class.trigger (CCScheduler.js:261)
    at Class.update (CCScheduler.js:167)
    at Class.update (CCScheduler.js:480)
    at Class.drawScene (CCDirector.js:226)
    at Class.mainLoop (CCDirector.js:884)
    at callback (CCBoot.js:2160)

【问题讨论】:

    标签: cocos2d-iphone cocos2d-x cocos2d-x-3.0 cocos2d-js


    【解决方案1】:

    在Sequence中,不能直接调用函数。添加 callFunc 或 callBlock

    这里是c++版本示例:

    auto scale = EaseElasticOut::create(ScaleTo::create(3.0f, 1.0f));
    auto calb = CallFunc::create( [this] () {
        this->check_basket_under( );
    });
    auto seq = Sequence::create(scale, calb, NULL);
    
    GameOverLabel->runAction(seq);
    

    更多信息谷歌CallFunc,CallFuncN在Sequence中的使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-21
      • 2012-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-04
      • 1970-01-01
      相关资源
      最近更新 更多