cocos2d对动画的各种操作
瞬时动作:瞬时动作的基类是InstantAction
1、放置位置 CGPoint p = ccp(width,height);
[sprite runAction:[CCPlace actionWithPosition:p]];
2、隐藏 [sprite runAction:[CCHide action]];
3、显示 [sprite runAction:[CCShow action]];
(效果类似亍 [node setVisible:YES]. 之所以作为一个劢作来实现是为了可以不其 他劢作形成一个连续劢作)
4、可见切换 [sprite runAction:[CCToggleVisibility action]];
延时动作:延时动作的基类是CCIntervalAction
函数命名规则:
XxxxTo: 意味着运劢到指定癿位置。
XxxxBy:意味着运劢到按照指定癿x、y增量癿位置。(x、y可以是负值)
1、移动到 – CCMoveTo
2、移动– CCMoveBy
3、跳跃到 – CCJumpTo 设置终点位置和跳跃癿高度和次数。
4、跳跃 – CCJumpBy 设置终点位置和跳跃癿高度和次数。
5、贝塞尔 – CCBezierBy 支持3次贝塞尔曲线:P0-起点,P1-起点切线方向,P2-终 点切线方向,P3-终点。 首先设置定Bezier参数,然后执行。
6、放大到 – CCScaleTo 设置放大倍数,是浮点型。
7、放大 – CCScaleBy
8、旋转到 – CCRotateTo
9、旋转 – CCRotateBy
10、闪烁 – CCBlink 设定闪烁次数
11、色调变化到 – CCTintTo
12、色调变换 – CCTintBy
13、变暗到 – CCFadeTo
14、由无变亮 – CCFadeIn
15、由亮变无 – CCFadeOut
组合动作:
1、序列-CCSequence
// 创建5个劢作
id ac0 = [sprite runAction:[CCPlace actionWithPosition:p]];
id ac1 = [CCMoveTo actionWithDuration:2 position:ccp(50,50)];
id ac2 = [CCJumpTo actionWithDuration:2 position:ccp(150,50) height:30 jumps:5];
id ac3 = [CCBlink actionWithDuration:2 blinks:3];
id ac4 = [CCTintBy actionWithDuration:0.5 red:0 green:255 blue:255];
//将5个劢作组合为一个序列,注意丌要忘了用nil结尾。
[sprite runAction:[CCSequence actions:ac0, ac1, ac2, ac3, ac4, ac0, nil]];
2、同步-Spawn
// 同步 劢作和组合劢作 以形成一个连续癿新劢作
[sprite runAction:[CCSpawn actions:ac1, ac2, seq, nil]];
3、重复有限次数 -Repeate
// 创建劢作序列
id ac1 = [CCMoveTo actionWithDuration:2 position:ccp( 50,50)];
id ac2 = [CCJumpBy actionWithDuration:2 position:ccp(-400, -200) height:30 jumps:5];
id ac3 = [CCJumpBy actionWithDuration:2 position:ccp(2, 0) height:20 jumps:3];
id seq = [CCSequence actions:ac1, ac2, ac3, nil];
// 重复运行上述劢作序列3次。
[sprite runAction:[CCRepeat actionWithAction:seq times:3]];
4、反动作-Reverse
反动作就是反向(逆向)执行某个动作,支持针对动作序列癿反劢作序列。反动作
不是一个与门的类,而是CCFiniteAction引入的一个接口。不是所有的类都支持
反动作,XxxxTo类通常不支持反动作,XxxxBy类通常支持。
id ac1 = [CCMoveBy actionWithDuration:2 position:ccp(190,220)];
// 创建某个动作的反动作。
id ac2 = [ac1 reverse];
[sprite runAction:[CCRepeat actionWithAction:[CCSequence actions:ac1, ac2,nil] times:2]];
动画-Animation
CCAnimation *animation = [AtlasAnimation animationWithName:@"flight" delay:0.2f];
// 每帧癿内容定义。
for(int i=0;i<3;i++) {
int x= i % 3;
[animation addFrameWithRect: CGRectMake(x*32, 0, 31, 30) ];
}
// 执行劢画效果
id action = [CCAnimate actionWithAnimation: animation];
[sprite runAction:[CCRepeat actionWithAction:action times:10]];
无限重复 - RepeatForever
// 将该动画作为精灵的本征动画,一直运行。
[sprite runAction:[RepeatForever actionWithAction:action]];
速度变化
1、EaseIn 由慢至快。
2、EaseOut 由快至慢
3、EaseInOut 由慢至快再由快至慢。
4、EaseSineIn 由慢至快。
5、EaseSineOut 由快至慢
6、EaseSineInOut 由慢至快再由快至慢。
7、EaseExponentialIn 由慢至极快。
8、EaseExponentialOut 由极快至慢。
9、EaseExponentialInOut 由慢至极快再由极快至慢。
10、Speed 人工设定速度,还可通过SetSpeed不断调整。
延时动作 - Delay
id ac1 = [CCMoveBy actionWithDuration:2 position:ccp(200, 200)];
id ac2 = [ac1 reverse];
// 实现一个等待间歇
[sprite runAction:[Sequence actions:ac1, [DelayTime actionWithDuration:1], ac2, nil]];
函数调用
id ac1 = [CCMoveBy actionWithDuration:2 position:ccp(200, 200)];
id ac2 = [ac1 reverse];
id acf = [CCCallFunc actionWithTarget:self selector:@selector(CallBack1)];
[sprite runAction:[CCSequence actions:ac1, acf, ac2, nil]];
1、带对象参数
id acf = [CallFuncN actionWithTarget:self selector:@selector(CallBack2:)];
- (void) CallBack2:(id)sender;
2、带对象、数据参数
id acf = [CCCallFuncND actionWithTarget:self selector:@selector(CallBack3:data:) data:(void*)2];
-(void) CallBack3:(id)sender data:(void*)data;
创建动作
1、利用文件名
CCAnimation*anim=[CCAnimationanimationWithFile:@"Jun"frameCount:12delay:0.1];
CCAnimate* animate = [CCAnimate actionWithAnimation:anim];
CCSequence *seq = [CCSequence actions:animate,nil];
CCRepeatForever* repeat = [CCRepeatForever actionWithAction:seq];
[sprite runAction:repeat];
2、利用缓存
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"Jun.plist"];
anim=[CCAnimation animationWithFrame:@"Jun" frameCount:12 delay:0.1];
animate = [CCAnimate actionWithAnimation:anim];
seq = [CCSequence actions:animate,nil];
repeat = [CCRepeatForever actionWithAction:seq];
[sprite runAction:repeat];
控制动作的速度
1、创建
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"Jun.plist"];
CCSprite*sprite=[CCSprite spriteWithSpriteFrameName:@"Jun1.png"];
sprite.position=ccp(200,200);
[self addChild:sprite];
CCAnimation*anim=[CCAnimation animationWithFrame:@"Jun" frameCount:12 delay:0.1];
CCAnimate* animate = [CCAnimate actionWithAnimation:anim];
CCSequence *seq = [CCSequence actions:animate,nil];
//动作放入speed中
CCSpeed *speed =[CCSpeed actionWithAction:[CCRepeatForever actionWithAction:seq] speed:1.0f];
[speed setTag:66];
[Sprite runAction:speed];
2、改变
CCSpeed *speed=(CCSpeed*)[sprite getActionByTag:66];
[speed setSpeed:0.5];//放慢原有速度的0.5倍
cocos2d对动画的各种操作的更多相关文章
- [cocos2d] 调用动画方法
利用texture atlases生成动画 中讲到如何添加动画,如果想要调用已添加的动画怎么办? 在1.0.1版本以前的cocos2d添加动画的方法为: CCAnimation *anim = [CC ...
- Day048--jQuery自定义动画和DOM操作
内容回顾 BOM location.reload() 全局刷新页面 location.href location.hash location.pathname location.hostname lo ...
- jQuery - 02. 样式表属性操作/类操作、动画、显示隐藏、滑入、淡入、停止动画、节点操作、添加对象、清空节点
样式表属性操作.css $("div").css({'width':100,'height':100,'background':'red'}); $("div" ...
- cocos2d+TexturePackerGUI动画制作
转载请注明出处:http://blog.csdn.net/oyangyufu/article/details/25168047 程序效果图: 1.下载安装TexturePackerGUI 地址:htt ...
- COCOS2D中对精灵的操作、对图片的各种操作
内容简要: 1.初始化 2.创建无图的精灵 3.设置精灵贴图大小 4.添加入层中 5.对精灵进行缩放 6.对精灵宽或高进行缩放 7.旋转精灵 8.设置精灵透明度 9.精灵的镜像反转 10.设 ...
- UITableViewController 滚动引起的cocos2d动画暂停问题的解决
UITableViewController 滚动引起的cocos2d动画暂停问题的解决 之前在使用UITableViewController进行滚动时,cocos2d的动画会暂停,直至滚动完毕才会继续 ...
- WPF 耗时操作时,加载loging 动画 (BackgroundWorker 使用方法)
1.定义一个全局 BackgroundWorker private System.ComponentModel.BackgroundWorker bgMeet0; 2.设置执行耗时的任务为True b ...
- Android动画效果之初识Property Animation(属性动画)
前言: 前面两篇介绍了Android的Tween Animation(补间动画) Android动画效果之Tween Animation(补间动画).Frame Animation(逐帧动画)Andr ...
- 深入学习jQuery动画控制
× 目录 [1]动画状态 [2]停止动画 [3]动画延迟[4]全局控制 前面的话 jQuery动画可以使用fade.hide.slide等方法实现基本动画效果,可以使用animate实现自定义动画,甚 ...
随机推荐
- VB动态添加WebBrowser控件,并拦截弹出窗口(不用引用任何组件)
新建空白窗体,然后粘帖下面代码: Option ExplicitPublic WithEvents br As VBControlExtender Private Sub br_ObjectEvent ...
- BLE GATT规范中关于UUID与属性的详细解析
1. 角色 除了GAP定义了角色之外,BLE还定义了另外2种角色:GATT服务器和GATT客户端,它们完全独立于GAP的角色.提供数据的设备称为GATT服务器,访问GATT服务器而获得数据的设备称为G ...
- 那些证书相关的玩意儿(SSL,X.509,PEM,DER,CRT,CER,KEY,CSR,P12等)[zz]
openssl dgst –sign privatekey.pem –sha1 –keyform PEM –c c:\server.pem 将文件用sha1摘要,并用privatekey.pem中的私 ...
- 用Java操作树莓派!pi4j简介与安装
简介 对C不熟?习惯了使用java不想换语言,但又想操作树莓派?想一边喝咖啡,一边吃树莓派蛋糕?快来使用pi4j吧! pi4j旨在为java开发者提供面友好的面向对象的API,来操控树莓派.pi4j对 ...
- Intersection of Two Linked Lists | LeetCode
利用两个栈,然后分别存储每一个链表. 继而,相继pop相同的节点. 有些细节需要注意,请看最后的返回值是如何处理的. /** * Definition for singly-linked list. ...
- ASP.NET MVC4中用 BundleCollection使用问题手记
ASP.NET MVC4中对JS和CSS的引用又做了一次变化,在MVC3中我们这样引用资源文件: <link href="@Url.Content("~/Content/Si ...
- A+Bproblem
package A+Bproblem; /* * A+B Problem 时间限制:3000 ms | 内存限制:65535 KB 难度:0 描述 此题为练手用题,请大家计算一下a+b的值 输入 ...
- OO之美2
面向对象并没有想象中那么神秘,以生活的现实眼光来看更是如此.把面向对象深度浓缩起来,可以概括为: ⑴目标:重用,扩展,兼容 ⑵核心:低耦合,高内聚 ⑶手段:封装变化 ⑷思想:面向接口编程,面向抽象编程 ...
- Ubuntu 14.04安装OpenCV 3.1
从OpenCV官网上下载OpenCV官网上下载OpenCV的未编译源代码: 点击这里 国内很多网络打开OpenCV官网速度缓慢,可以点击如下地址直接从GitHub上下载OpenCV 3.1的源代码 下 ...
- Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given the below binary tree andsum =
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all ...