~~~~我的生活,我的点点滴滴!!
Action的动作实在太多太多了,有40-50种,自由组合等能出的更多,这里没有全部列下来,只是简单的列了下面几种。
更详细的讲解请看 http://blog.csdn.net/ac_huang/article/details/37972017
1、简单的快慢移动效果
void SpriteEase::onEnter() { EaseSpriteDemo::onEnter(); //创建一个相对移动,即在3s内,x轴移动VisibleRect::right().x-130,y轴移动0 auto move = MoveBy::create(3, Vec2(VisibleRect::right().x-130,0)); //最快捷的反向运动,move动作的反向动作,即移动到位后,在原路返回 auto move_back = move->reverse(); // EaseIn 由慢至快。 auto move_ease_in = EaseIn::create(move->clone(), 2.5f); auto move_ease_in_back = move_ease_in->reverse(); // EaseOut 由快至慢。 auto move_ease_out = EaseOut::create(move->clone(), 2.5f); auto move_ease_out_back = move_ease_out->reverse(); auto delay = DelayTime::create(0.25f); //注意看第二个参数为delay与第四个为delay->clone(),后面全是他的复制品,仔细看源码,他里面有一个 //保存此对象(delay)的动作,即赋值。如果不使用clone,那么全是一个对象指针,后续操作会全乱。 //delay->clone()为深度复制,即不是简单的改变指针指向,复制他的一切(包括动作、形为、监听等) //下面这个动作组是:移动----等待----返回 auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), nullptr); auto seq2 = Sequence::create(move_ease_in, delay->clone(), move_ease_in_back, delay->clone(), nullptr); auto seq3 = Sequence::create(move_ease_out, delay->clone(), move_ease_out_back, delay->clone(), nullptr); //RepeatForever永久运动,但是后面使用stopAction来停止 auto a2 = _grossini->runAction(RepeatForever::create(seq1)); a2->setTag(1); auto a1 = _tamara->runAction(RepeatForever::create(seq2)); a1->setTag(1); auto a = _kathia->runAction(RepeatForever::create(seq3)); a->setTag(1); //用来停止上面三个精灵的移动 schedule(schedule_selector(SpriteEase::testStopAction), 6.25f); } void SpriteEase::testStopAction(float dt) { //停止 unschedule(schedule_selector(SpriteEase::testStopAction)); _tamara->stopActionByTag(1); _kathia->stopActionByTag(1); _grossini->stopActionByTag(1); }
2、带有弹性的移动
void SpriteEaseElastic::onEnter() { EaseSpriteDemo::onEnter(); auto move = MoveBy::create(3, Vec2(VisibleRect::right().x-130, 0)); auto move_back = move->reverse(); //让目标动作赋予弹性 ,且以目标动作起点位子赋予弹性 auto move_ease_in = EaseElasticIn::create(move->clone() ); auto move_ease_in_back = move_ease_in->reverse(); //让目标动作赋予弹性 ,且以目标动作终点位子赋予弹性 auto move_ease_out = EaseElasticOut::create(move->clone() ); auto move_ease_out_back = move_ease_out->reverse(); auto delay = DelayTime::create(0.25f); auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), nullptr); auto seq2 = Sequence::create(move_ease_in, delay->clone(), move_ease_in_back, delay->clone(), nullptr); auto seq3 = Sequence::create(move_ease_out, delay->clone(), move_ease_out_back, delay->clone(), nullptr); _grossini->runAction( RepeatForever::create(seq1)); _tamara->runAction( RepeatForever::create(seq2)); _kathia->runAction( RepeatForever::create(seq3)); }
3、带有反弹的物体运动
void SpriteEaseElasticInOut::onEnter() { EaseSpriteDemo::onEnter(); auto move = MoveBy::create(3, Vec2(VisibleRect::right().x-130, 0)); //让目标动作赋予弹性 ,且以目标动作起点和终点位子赋予弹性 auto move_ease_inout1 = EaseElasticInOut::create(move->clone(), 0.3f); auto move_ease_inout_back1 = move_ease_inout1->reverse(); //让目标动作赋予弹性 ,且以目标动作起点和终点位子赋予弹性 auto move_ease_inout2 = EaseElasticInOut::create(move->clone(), 0.45f); auto move_ease_inout_back2 = move_ease_inout2->reverse(); auto move_ease_inout3 = EaseElasticInOut::create(move->clone(), 0.6f); auto move_ease_inout_back3 = move_ease_inout3->reverse(); auto delay = DelayTime::create(0.25f); auto seq1 = Sequence::create(move_ease_inout1, delay, move_ease_inout_back1, delay->clone(), nullptr); auto seq2 = Sequence::create(move_ease_inout2, delay->clone(), move_ease_inout_back2, delay->clone(), nullptr); auto seq3 = Sequence::create(move_ease_inout3, delay->clone(), move_ease_inout_back3, delay->clone(), nullptr); _tamara->runAction( RepeatForever::create(seq1)); _kathia->runAction( RepeatForever::create(seq2)); _grossini->runAction( RepeatForever::create(seq3)); } void SpriteEaseBounce::onEnter() { EaseSpriteDemo::onEnter(); auto move = MoveBy::create(3, Vec2(VisibleRect::right().x-130, 0)); auto move_back = move->reverse(); //让目标动作赋予反弹力,且以目标动作开始位子开始反弹 auto move_ease_in = EaseBounceIn::create(move->clone() ); auto move_ease_in_back = move_ease_in->reverse(); //让目标动作赋予反弹力,且以目标动作结束位子开始反弹 auto move_ease_out = EaseBounceOut::create(move->clone() ); auto move_ease_out_back = move_ease_out->reverse(); auto delay = DelayTime::create(0.25f); auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), nullptr); auto seq2 = Sequence::create(move_ease_in, delay->clone(), move_ease_in_back, delay->clone(), nullptr); auto seq3 = Sequence::create(move_ease_out, delay->clone(), move_ease_out_back, delay->clone(), nullptr); _grossini->runAction( RepeatForever::create(seq1)); _tamara->runAction( RepeatForever::create(seq2)); _kathia->runAction( RepeatForever::create(seq3)); } void SpriteEaseBounceInOut::onEnter() { EaseSpriteDemo::onEnter(); auto move = MoveBy::create(3, Vec2(VisibleRect::right().x-130, 0)); auto move_back = move->reverse(); //让目标动作赋予反弹力,且以目标动作结束位子开始反弹 auto move_ease = EaseBounceInOut::create(move->clone() ); auto move_ease_back = move_ease->reverse(); auto delay = DelayTime::create(0.25f); auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), nullptr); auto seq2 = Sequence::create(move_ease, delay->clone(), move_ease_back, delay->clone(), nullptr); this->positionForTwo(); _grossini->runAction( RepeatForever::create(seq1)); _tamara->runAction( RepeatForever::create(seq2)); }
弹,或者开始与结束时都反弹。