同时执行使用Spawn
顺序执行使用Sequence
在RPG游戏中,有时候会遇到角色拾捡地上掉落的金币,金币的数量会上飘的同时逐渐显示出来,然后停了一小会时间,在消失掉。棋牌游戏中玩家输赢的金币也是如此,在玩家头上显示+赢-输的金币数量,上飘一点距离同时逐渐显示出来,停留一会后立马消失掉。下面是实现的代码。
//逐渐显示AtlasLabel数字结果,然后消失
void LoginScene::fadeInRes(string num)
{
Sprite* sp = static_cast<Sprite *>(this->csb->getChildByName("sp_res"));
Vec2 pos = sp->getPosition();
sp->setVisible(true);
sp->setOpacity(0);
auto res = static_cast<TextAtlas *>(sp->getChildByName("AtlasLabel_res"));
res->setStringValue(num);
MoveTo* mt = MoveTo::create(0.8f, Vec2(pos.x, pos.y + 150));
FadeIn* fin = FadeIn::create(1.0f);
FadeOut* out = FadeOut::create(0.01f);
sp->runAction(Sequence::create(Spawn::create(fin, mt), DelayTime::create(1.0f), out, NULL));
}
用到的资源节点: