多个序列上的 runAction

runAction on multiple sequences

这是我的代码:

if (sprite != NULL)
{
    delay1 = CCDelayTime::create(1.5f);
    delay2 = CCDelayTime::create(3.0f);
    brickdelete = CallFunc::create([this]()
    {
        sprite->setOpacity(0);
        sprite->getPhysicsBody()->removeFromWorld();
    });
    brickcreate = CallFunc::create([this]()
    {
        sprite->setOpacity(255);
        sprite->setPhysicsBody(brickbody);
    });
    disintegratefunction = CallFunc::create([this]() {
        sprite->runAction(disintegrateAnim);
    });
    appearfunction = CallFunc::create([this]() {
        sprite->runAction(appearAnim);
    });
    runAction(Sequence::create(disintegratefunction, delay1, brickdelete, delay2, appearfunction, brickcreate, NULL));
}

我希望同时发生多个 runAction 实例。目前,如果我启动一个 runAction 而另一个正在进行,我会得到多个断言失败并且第一个序列中的剩余操作被添加到第二个 runAction 序列(因此第一个主体在序列的某个阶段仍然不完整)。

我希望他们彼此独立。这可能吗?我也试过 targetedaction 但我不确定代码是否正确,因为它有相同的结果。

Sequence会运行一个动作接一个动作,要同时运行个动作需要使用Spawn.

Spawn is very similar to Sequence, except that all actions will run at the same time. You can have any number of Action objects and even other Spawn objects!

所以在你的例子中:

if (sprite != NULL)
{
    delay1 = CCDelayTime::create(1.5f);
    delay2 = CCDelayTime::create(3.0f);
    brickdelete = CallFunc::create([this]()
    {
        sprite->setOpacity(0);
        sprite->getPhysicsBody()->removeFromWorld();
    });
    brickcreate = CallFunc::create([this]()
    {
        sprite->setOpacity(255);
        sprite->setPhysicsBody(brickbody);
    });
    disintegratefunction = CallFunc::create([this]() {
        sprite->runAction(disintegrateAnim);
    });
    appearfunction = CallFunc::create([this]() {
        sprite->runAction(appearAnim);
    });
    runAction(Spawn::create(disintegratefunction, delay1, brickdelete, delay2, appearfunction, brickcreate));
}

参考:http://www.cocos2d-x.org/docs/cocos2d-x/en/actions/sequences.html