这是我的代码:
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序列(因此第一个主体在序列的某个阶段仍然不完整)。
我希望他们彼此独立。这可能吗?我也尝试过有针对性的行动,但我不确定代码是否合适,因为它有相同的结果。
答案 0 :(得分:1)
Sequence
将在另一个之后运行一个操作,以便在您需要使用Spawn
的同时运行操作。
Spawn与Sequence非常相似,只是所有动作都会在 同一时间。你可以拥有任意数量的Action对象 其他Spawn对象!
所以在你的例子中:
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