Cocos-2d-x 学习笔记二(Action篇)
来源:互联网 发布:网络剧小心超人与伽罗 编辑:程序博客网 时间:2024/05/16 17:37
Cocos-2d-x学习笔记二
1.Action类
- ActionInterval example:
Flipx()
ActionInstant
是瞬时动作类,表示瞬间完成,中间没有动画效果,Flipx()
就是它的一个例子,当物体走到障碍物时会有一个转向的过程,这可以通过Flipx
的动作效果,以下是code:
//创建移动动作ActionInterval *moveto = MoveTo::create(5, Vec2(0, 200));// 创建X轴方向的翻转动作ActionInstant *flipx = FlipX::create(true);ActionInterval *moveback = MoveTo::create(5, Vec2(visibleSize.width, 200));auto player=Sprite::create("player.png");player->setPosition(Point(visibleSize.width/2,200));auto action = Sequence::create(moveto, flipx, moveback, flipx->reverse(), NULL); player->runAction(action);
- 延时动作
即之前所提到的MoveBy,MoveTo会在指定时间内完成,中间会有动画效果,本次要将的是如何实现贝塞尔曲线的运动效果,它需要一个起点,终点,控制点,和控制线sample,代码实现如下:
ccBezierConfig beizer; beizer.controlPoint_1 = Point(200, 300); beizer.controlPoint_2 = Point(400, 400); beizer.endPosition = Point(50, 200); auto beizierAction = BezierTo::create(2.0f,beizer); auto dog = Sprite::create("player.png"); dog->setPosition(Point(visibleSize.width / 2, 200)); this->addChild(dog); dog->runAction(beizierAction);
额,后面会讲到一个JumpBy
和JumpTo
类所以就在这里先介绍一下,其create后面有4个参数,第一个是执行的时间,第二个是一个对象的坐标,代表跳完最后落在的坐标(以原来对象所处位置为原点的相对坐标系)
- ActionEase 缓冲效果
该类有5类运动:指数缓冲,Sine缓冲,弹性缓冲,跳跃缓冲,回震缓冲,每类运动都包含了3个不同时期的变换:In,Out,InOut,(其中in代表开始时加速,out代表结尾时加速),以下是样例:
ActionInterval *moveto1 = MoveTo::create(5, Vec2(50, 100));ActionInterval *moveto2 = MoveTo::create(5, Vec2(50, 300));ActionInterval *moveto3 = MoveTo::create(5, Vec2(50, 500));auto scene = Director::getInstance()->getRunningScene();auto layer = scene->getChildByTag(1);auto dog1 = layer->getChildByTag(1);auto dog2 = layer->getChildByTag(2);auto dog3 = layer->getChildByTag(3);auto action1 = EaseExponentialIn::create(moveto1);auto action2 = EaseExponentialOut::create(moveto2);auto action3 = EaseExponentialInOut::create(moveto3);dog1->runAction(action1);dog2->runAction(action2);dog3->runAction(action3); //我在vs上跑的时候为什么先执行第二个函数
组合动作
sequence和spawn在上一次中已经讲过了,所以这次讲一下Repeat
和RepeatForever
类。repeat
类可以指定重复次数。代码示例如下:auto jumpto1 = JumpBy::create(3, Vec2(0, 0), 100, 1);auto jumpto2 = JumpBy::create(3, Vec2(0, 0), 100, 1);auto player1 = Sprite::create("player.png");auto player2 = Sprite::create("player.png");player1->setPosition(Point(visibleSize / 3));player1->setPosition(Point(visibleSize * 2 / 3));this->addChild(player1);this->addChild(player2);auto repeatJump = Repeat::create(jumpto1, 5);auto repeatForeverJump = RepeatForever::create(jumpto2);player1->runAction(repeatJump);player2->runAction(repeatForeverJump);
其实还有一个
callfunc
类没有写,但是目前还是没有完全搞懂这一个系列的东西的作用到底是啥,所以就先不写了。。。
0 0
- Cocos-2d-x 学习笔记二(Action篇)
- cocos-2d-x学习笔记
- COCOS-2d-x学习之路(Lua)
- Cocos 2d-x 学习第三天
- quick-cocos-2d-x学习
- cocos2d-x学习笔记-cocos-2d-2.0.4交叉编译
- Cocos 2d 笔记
- cocos-2d-x 资料
- cocos 2d-x 动作
- 学习记录:cocos 2d-x 飞机游戏开发
- cocos 2dx 3.12 学习笔记(二) Sprite
- Cocos 3D功能初探学习笔记(2)---3D精灵
- Cocos 3D功能初探学习笔记(1)---摄像机
- Cocos 3D功能初探学习笔记(3)---光照
- Cocos 2d TestCPP 学习
- Cocos 2d-x Console模块
- cocos 2d-x 中文乱码
- cocos 2d-x 3.0环境配置
- Mongodb之——CentOS安装Mongodb
- 动态规划专题之---- Unique Binary Search Trees
- 数独求解算法
- Linux wc命令
- Linq教程
- Cocos-2d-x 学习笔记二(Action篇)
- [概念笔记] Redis
- log4php日志插件
- python中遍历文件的3个方法
- 初始化NavigationView HeaderView中控件
- 深度学习平台Caffe环境搭建【CPU版】
- 数字分解为不同自然数的最大乘积
- Vue.js——vue-resource全攻略
- 【BZOJ 4810】【YNOI 2017】由乃的玉米田【莫队+bitset】