【发布时间】:2015-05-28 09:04:02
【问题描述】:
我正在尝试使用 cocos2d-x 制作动画序列。我想将精灵一个接一个地向下移动一定距离。
这是我的第一次尝试:
auto fallAction = MoveBy::create(0.2f, Vec2(0, -director->getWinSize().height));
auto fallActionEase = EaseIn::create(fallAction, 2.0f);
auto fallStretch = ScaleBy::create(0.1f, 1.0f, 1.2f);
auto fall = Spawn::create(fallActionEase, fallStretch, NULL);
auto landTremble = EaseElasticOut::create(ScaleTo::create(0.5f, _finalScale));
this->getK()->runAction(Sequence::create(Delay::create(0.5f), fall, landTremble));
this->getA()->runAction(Sequence::create(Delay::create(1.0f), fall, landTremble));
this->getW()->runAction(Sequence::create(Delay::create(1.5f), fall, landTremble));
但它不起作用,正如 [此处] (Reuse cocos2d actions) 所讨论的那样。
然后我发现I can copy actions,但后来我也发现 Clonable::copy() 现在已弃用(似乎它甚至在 v3.6 中都不存在!)
我最终嵌套了 lambda,例如 here(第 246 到 254 行。)
我想以良好的方式“重用”actions!我想要达到的目标如下:
- 制作与上述完全相同的动画
- 仍然是
creating只有一个Action来确定精灵的运动 - 易于维护的代码
编辑: 为了防止链接失效,我将把代码粘贴到我嵌套 lambda 的位置。不是很聪明。
auto DesiredAction = Sequence::create(wait4Frog, Fall, Spawn::create(FallSound, LandTremble,CallFunc::create([this, Fall, LandTremble](){
this->getA1()->runAction(Sequence::create(Fall, Spawn::create(LandTremble,CallFunc::create([this, Fall, LandTremble](){
this->getW()->runAction(Sequence::create(Fall, Spawn::create(LandTremble,CallFunc::create([this, Fall, LandTremble](){
this->getA2()->runAction(Sequence::create(Fall, Spawn::create(LandTremble,CallFunc::create([this, Fall, LandTremble](){
this->getZ()->runAction(Sequence::create(Fall, LandTremble, NULL));
}), NULL), NULL));
}), NULL), NULL));
}), NULL), NULL));
}), NULL), NULL);
【问题讨论】: