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实现自定义动画,甚 ...
随机推荐
- [收藏]Asp.net MVC生命周期
一个HTTP请求从IIS移交到Asp.net运行时,Asp.net MVC是在什么时机获得了控制权并对请求进行处理呢?处理过程又是怎样的? 以IIS7中asp.net应用程序生命周期为例,下图是来自M ...
- 出现upstream sent too big header while reading response header from upstream错误
一个POS系统,出现upstream sent too big header while reading response header from upstream错误. 1.反向代理端,可以放到se ...
- android source compiler
- VB的判断语句和循环语句
判断语句 •If语句 if语句共有4种写法: 第一种语法: If 条件判断语句 then 程序代码 第二种语法:If 条件判断语句 then 程序代码 else 程式代码 第三种语法: If 条件 ...
- 设计模式:组合模式(Composite)
定 义:将对象组合树形结构以表示“部分-整体”的层次结构.组合模式使得用户对单个对象和组合对象使用具有一致性. 结构图: Component类: abstract class Component ...
- 比较java与c语言中数字转换成字符的不同
java java中将数字转换成字符非常方便,只要用一个"+"然后在跟一个空格行了.比如,你输入一个122 ,就会变成"122 ". import java.u ...
- Magento修改邮件模板内容
Magento 默认邮件模板 都是带着官方的标志和一些官方的基本信息.为了建立品牌形象我们需要把邮件模板中的所有官方信息换成自己的信息.修改步骤如下: 1.找到Magento的邮件模板文件(这里以 e ...
- Android开发笔记-加载xml资源
1.Activity获取strings.xml中键的值 需要通过 getResources().getString(R.string.*)方法获得 以“state”为例 String value= g ...
- 【C++】利用指针实现通过函数改变多个参数的值
写惯了python,对于C++的语法越来越生疏,不同于python中函数可以return多个变量,C++的函数要想返回多个参数可以利用指针实现. 因为在函数内部的变量都是局部变量,所以当参数传入函数中 ...
- (转帖) java内存分配分析/栈内存、堆内存
http://blog.csdn.net/qh_java/article/details/9084091