CCSequence 在单独定义时不起作用 [英] CCSequence not working when defined separately

查看:21
本文介绍了CCSequence 在单独定义时不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In cocos2d-x, I have encountered the following problem when trying to define a CCSequence separately, i.e. not within 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 );

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

It does not cause a compiler error, or crash, or anything, it just doesn't rotate the sprite.

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

How can I fix this? (I am using this action multiple times, so it would really help to keep my code cleaner if I could define it only once)

推荐答案

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

A single instance of CCAction should not be used concurrently on multiple objects. The objects contained within the sequence maintain state on the current execution of the action, thus concurrent use on multiple objects will cause mayhem (cocos is possibly 'guarding' silently against that by stoping all actions, not certain). Best to have separate sequences for each sprite you want to animate. If you are concerned about code readability, just create a method in that class that will always return a fresh instance of the sequence.

这篇关于CCSequence 在单独定义时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆