c++ - 多个序列上的 runAction

标签 c++ cocos2d-x

这是我的代码:

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 将一个 Action 一个接一个地运行,要同时运行 Action ,您需要使用 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

关于c++ - 多个序列上的 runAction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50918732/

相关文章:

c++ - cocos2dx中如何将Sprite对象保存到文件中?

c++ - 我可以将一个对象类转换为它在其中实现的接口(interface)指针吗?

cross-platform - 如何在 Cocos2D-JS 中使用 native 3rd 方库?

c++ - 在 mpi 中定义全局变量

c++ - 使用 move::semantic 将大量 vector 合并为一个更大的 vector

c++ - Cocos2dx 2.2.3 架构 arm64::WebPInitDecoderConfigInternal 的 undefined symbol

cocos2d-x - RapidJson : How to get all Key_names from a JSON? (cocos2dx)

c++ - 类构造函数上的调用错误没有匹配函数

c++ - 为什么下面的代码没有给出想要的答案?

c++ - 0 当作为模板参数提供时不是有效的 FILE*