Cocos2d-x 3.10 学习笔记之缓冲动作
2017-04-19 本文已影响93人
Buckler
公司今天有个需求 需要做一个跑马灯抽奖的系统
还需要有一个缓慢停止的效果
百度了下没有找到3.10的例子 所以只能根据之前的API 重新在3.10里写一遍
参考:http://blog.csdn.net/zcmain/article/details/13631433
那么code如下:
//auto visibleSize = Director::getInstance()->getVisibleSize();
//auto spr = Sprite::create("images/WR_atk_tile.png");
//spr->setPosition(Vec2(0, 0));
//this->addChild(spr);
//auto move = MoveTo::create(3.0f, Vec2(visibleSize.width / 2, visibleSize.height / 2));
//spr->runAction(move);
///////////////////////////////////////////////////////////
///基本用法
///<1> In actions:action(开始的时候加速)
///<2> Out actions:action(结束的时候加速)
///<3> InOut actions:action(开始和结束的时候加速)
///////////////////////////////////////////////////////////
/*基本缓冲动作*/
//auto actionEaseIn = EaseIn::create(move, 2.5f);//缓慢开始
//auto actionEaseOut = EaseOut::create(move, 2.5f);//缓慢终止
//auto actionEaseInOut = EaseInOut::create(move, 2.5f);
//spr->runAction(actionEaseInOut);
/*指数缓冲动作*/
//auto actionIn = EaseExponentialIn::create(move);//缓慢开始
//auto actionOut = EaseExponentialOut::create(move);//缓慢终止
//auto actionInOut = EaseExponentialInOut::create(move);
//spr->runAction(actionInOut);
/*赛因缓冲动作*/
//auto actionSineIn = EaseSineIn::create(move);//由慢至快
//auto actionSineOut = EaseSineOut::create(move);//由快至慢
//auto actionSineInOut = EaseSineInOut::create(move);//由慢至快再至慢
//spr->runAction(actionSineInOut);
/*跳跃缓冲动作*/
//auto actionBounceIn = EaseBounceIn::create(move);//在起始位置开始反弹
//auto actionBounceOut = EaseBounceOut::create(move);//在结束位置开始反弹
//auto actionBounceInOut = EaseBounceInOut::create(move);//在起始位置和结束位置都反弹
//spr->runAction(actionBounceInOut);
/*弹性缓冲动作*/
//auto actionElasticIn = EaseElasticIn::create(move);//在起点位置赋予弹性
//auto actionElasticOut = EaseElasticOut::create(move);//在终点位置赋予弹性
//auto actionElasticInOut = EaseElasticInOut::create(move);//在起点和终点位置都赋予弹性
//spr->runAction(actionElasticInOut);
/*回震缓冲动作*/
//auto actionBackIn = EaseBackIn::create(move);//在起点位置作为回力点
//auto actionBackOut = EaseBackOut::create(move);//在终点位置作为回力点
//auto actionBackInOut = EaseBackInOut::create(move);//在起点和终点位置都作为回力点
//spr->runAction(actionBackOut);
///////////////////////////////////////////////////////////
///使用
///让一个精灵 执行组合的指数缓冲动作
///////////////////////////////////////////////////////////
auto visibleSize = Director::getInstance()->getVisibleSize();
//创建精灵
auto spr = Sprite::create("images/WR_atk_tile.png");
spr->setPosition(Vec2(100, 300));
this->addChild(spr);
//创建一个动作
auto move = MoveBy::create(3, Vec2(visibleSize.width, 0));
//根据这个动作创建指数缓冲动作
auto moveEaseIn = EaseExponentialIn::create(move);
//反向动作
auto moveEaseInBack = moveEaseIn->reverse();
//创建动作序列
auto sequence = Sequence::create(moveEaseIn, moveEaseInBack, nullptr);
spr->runAction(RepeatForever::create(sequence));