当单独定义时,CCSequence不工作 [英] CCSequence not working when defined separately

查看:120
本文介绍了当单独定义时,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 );

它不会导致编译器错误,崩溃或任何东西, sprite。

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)

推荐答案

p> CCAction的单个实例不应同时用于多个对象。包含在序列中的对象保持对当前执行动作的状态,因此对多个对象的并发使用将导致混乱(cocos可能通过停止所有动作而静静防止)。最好为你想要动画的每个sprite有单独的序列。如果你关心代码的可读性,只需在该类中创建一个方法,它总是返回一个新的序列实例。

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天全站免登陆