【问题标题】:cocos2dx - ActionTween not workingcocos2dx - ActionTween 不工作
【发布时间】:2015-05-08 12:04:45
【问题描述】:

在我的游戏中,我需要旋转硬币,因为我正在使用ActionTween,如下所示

auto animateTo=ActionTween::create(.4, "roll", 0.f, M_PI_2);
auto animateFrom=ActionTween::create(.4, "roll", M_PI_2, M_PI);
auto seq=Sequence::create(animateTo,animateFrom, NULL);
coin->runAction(seq); 

我已经实现了ActionTweenDelegate太喜欢了

class GameScene : Base, public ActionTweenDelegate

并实现方法

void updateTweenAction(float value, const std::string& key);

但每次我得到

断言失败:目标必须实现 ActionTweenDelegate 断言 失败:(dynamic_cast(target)),函数 startWithTarget

我已经尝试设置startTarget 以及像

animateTo->setOriginalTarget(this);
animateFrom->setOriginalTarget(this);

但没有运气,没有任何工作它每次都会崩溃。

如果有人遇到过同样的事情,请帮忙。

谢谢。

【问题讨论】:

    标签: ios cocos2d-x cocos2d-x-3.0 chipmunk


    【解决方案1】:

    这样做:

    ActionTweenDelegate(ActionTween 的协议)继承到您要对其执行ActionTween 的精灵类。

    也写

    void updateTweenAction(float value, const std::string& key);
    

    您班级的 .h.cpp 文件中的方法。

    一旦 ActionTween 运行,用值更新精灵的键属性;

    例子:

    MySprite *sprite = MySprite::create();
    sprite->runAction(ActionTween::create(1.0, "scaleX", 1.0, 0.0))
    

    在 MySprite.cpp 中

    void updateTweenAction(float value, const std::string& key) {
        this->setScaleX(value);
    }
    

    确保补间构造函数和回调中的键“scaleX”必须相同。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-02
      • 1970-01-01
      • 1970-01-01
      • 2017-05-21
      • 1970-01-01
      相关资源
      最近更新 更多