【问题标题】:CCSequence not working when defined separatelyCCSequence 在单独定义时不起作用
【发布时间】:2012-10-13 21:51:38
【问题描述】:

在cocos2d-x中,我在尝试单独定义CCSequence时遇到了如下问题,即不在runAction内。

这行得通:

sprWheel1->runAction(   CCSequence::actions(
    CCDelayTime::actionWithDuration( fDelayTime ),
    CCEaseExponentialOut::actionWithAction( 
        CCRotateBy::actionWithDuration( fMoveTime, fAngle ) ),
    NULL
) );
sprWheel2->runAction(   CCSequence::actions(
    CCDelayTime::actionWithDuration( fDelayTime ),
    CCEaseExponentialOut::actionWithAction( 
        CCRotateBy::actionWithDuration( fMoveTime, fAngle ) ),
    NULL
) );

这不起作用:

CCFiniteTimeAction* actRotate = CCSequence::actions(
    CCDelayTime::actionWithDuration( fDelayTime ),
    CCEaseExponentialOut::actionWithAction( 
        CCRotateBy::actionWithDuration( fMoveTime, fAngle ) ),
    NULL
);

sprWheel1->runAction( actRotate );
sprWheel2->runAction( actRotate );

它不会导致编译器错误、崩溃或任何事情,它只是不会旋转精灵。

我该如何解决这个问题? (我多次使用此操作,所以如果我只能定义一次,这将有助于保持我的代码更干净)

【问题讨论】:

    标签: cocos2d-iphone cocos2d-x


    【解决方案1】:

    不应在多个对象上同时使用单个 CCAction 实例。序列中包含的对象在当前执行动作时保持状态,因此在多个对象上同时使用会导致混乱(cocos 可能通过停止所有动作来默默地“保护”,但不确定)。最好为每个要制作动画的精灵设置单独的序列。如果您担心代码的可读性,只需在该类中创建一个始终返回序列的新实例的方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-20
      • 1970-01-01
      • 1970-01-01
      • 2018-08-06
      • 2021-06-12
      • 2018-06-20
      • 1970-01-01
      相关资源
      最近更新 更多