gpt4 book ai didi

c++ - 多个序列上的 runAction

转载 作者:行者123 更新时间:2023-11-28 04:37:47 26 4
gpt4 key购买 nike

这是我的代码:

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com