先看一下我实现的一个画面:
用到的知识:
***To: 意味着运动到指定的位置。
***By:意味着运动到按照指定癿 x、y 增量的位置。(x、y 可以是负值)
移动到 – CCMoveTo
移动– CCMoveBy
跳跃到 – CCJumpTo
设置终点位置和跳跃癿高度和次数。
跳跃 – CCJumpBy
设置终点位置和跳跃癿高度和次数。
放大到 – CCScaleTo
设置放大倍数,是浮点型。
放大 – CCScaleBy
旋转到 – CCRotateTo
旋转 – CCRotateBy
闪烁 – CCBlink
色调变化到 – CCTintTo
色调变换 – CCTintBy
变暗到 – CCFadeTo
由无变亮 – CCFadeIn
由亮变无 – CCFadeOut
上代码:
/***********添加各种标签***********/
//1 helloWorld标签
CCLabelTTF *hello = [CCLabelTTF labelWithString:@"Hello World" fontName:@"Marker Felt" fontSize:30];
// 屏幕大小
CGSize size = [[CCDirector sharedDirector] winSize];
// 标签位置
hello.position = ccp( size.width /2 , size.height/2 );
// 添加标签
[self addChild: hello];
//2跳标签
CCLabelTTF *jumpL = [CCLabelTTF labelWithString:@"jump" fontName:@"Marker Felt" fontSize:30];
jumpL.position = ccp(size.width / 2,jumpL.textureRect.size.height / 2);
[self addChild:jumpL];
//3旋转标签
CCLabelTTF *rotateL = [CCLabelTTF labelWithString:@"rotate" fontName:@"Marker Felt" fontSize:30];
rotateL.position = ccp(size.width / 2, size.height / 2 + hello.textureRect.size.height);
[self addChild:rotateL];
//4闪烁出现标签
CCLabelTTF *blinkL = [CCLabelTTF labelWithString:@"blink" fontName:@"Marker Felt" fontSize:30];
blinkL.position = ccp(size.width / 2, size.height - blinkL.textureRect.size.height / 2);
[self addChild:blinkL];
//5悬挂标签
CCLabelTTF *hangL = [CCLabelTTF labelWithString:@"hang" fontName:@"Marker Felt" fontSize:30];
hangL.position = ccp(hangL.textureRect.size.width / 2, size.height - hangL.textureRect.size.height / 2);
[self addChild:hangL];
//6放大、缩小标签
CCLabelTTF *scaleL = [CCLabelTTF labelWithString:@"scale" fontName:@"Marker Felt" fontSize:30];
scaleL.position = ccp(size.width - scaleL.textureRect.size.width,size.height - scaleL.textureRect.size.height );
[self addChild:scaleL];
//7有无变有,有有变无标签
CCLabelTTF *fadeL = [CCLabelTTF labelWithString:@"fade" fontName:@"Marker Felt" fontSize:30];
fadeL.position = ccp(size.width / 4, size.height / 2);
[self addChild:fadeL];
//8动画,小人在走
CCSpriteBatchNode *mgr = [CCSpriteBatchNode batchNodeWithFile:@"xiaoren.png" capacity:5];
CCSpriteBatchNode *mgr1 = [CCSpriteBatchNode batchNodeWithFile:@"xiaorenzou.png" capacity:5];
CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:mgr.texture rect:CGRectMake(0, 0, 57, 57)];
CCSpriteFrame *frame1 = [CCSpriteFrame frameWithTexture:mgr1.texture rect:CGRectMake(0, 0, 57, 57)];
CCAnimation *animation = [CCAnimation animationWithSpriteFrames:[NSArray arrayWithObjects:frame,frame1, nil] delay:0.2f];
id action = [CCAnimate actionWithAnimation:animation];
CCSprite *sprite = [CCSprite spriteWithSpriteFrame:frame];
sprite.position = ccp(size.width / 4,size.height / 4 );
[self addChild:sprite];
[sprite runAction:[CCRepeatForever actionWithAction:action]];
//再叠加一个动作,四周走动
CCMoveTo *moveto1 = [CCMoveTo actionWithDuration:2 position:ccp(size.width / 4,size.height / 4 * 3)];
CCMoveTo *moveto2 = [CCMoveTo actionWithDuration:2 position:ccp(size.width / 4 * 3,size.height / 4 * 3)];
CCMoveTo *moveto3 = [CCMoveTo actionWithDuration:2 position:ccp(size.width / 4 * 3,size.height / 4)];
CCMoveTo *moveto4 = [CCMoveTo actionWithDuration:2 position:ccp(size.width / 4,size.height / 4 )];
CCSequence *sequenceMove = [CCSequence actions:moveto1,moveto2,moveto3,moveto4, nil];
[sprite runAction:[CCRepeatForever actionWithAction:sequenceMove]];
/********标签的各种动作*********/
//1、hello world标签变色
CCTintTo *tint1 = [CCTintTo actionWithDuration:2 red:255 green:0 blue:0];
CCTintTo *tint2 = [CCTintTo actionWithDuration:2 red:255 green:255 blue:0];
CCTintTo *tint3 = [CCTintTo actionWithDuration:2 red:0 green:255 blue:0];
CCTintTo *tint4 = [CCTintTo actionWithDuration:2 red:0 green:255 blue:255];
CCTintTo *tint5 = [CCTintTo actionWithDuration:2 red:0 green:0 blue:255];
CCTintTo *tint6 = [CCTintTo actionWithDuration:2 red:255 green:0 blue:255];
//顺序添加到ccsequence类中
CCSequence *tintSequence = [CCSequence actions:tint1,tint2,tint3,tint4,tint5,tint6, nil];
//不断的循环次动作
CCRepeatForever *repeatTint = [CCRepeatForever actionWithAction:tintSequence];
//最后运行
[hello runAction:repeatTint];
//2、jump标签跳跳,height是跳的高度,jumps参数是速度越大越快(你可以改大了试试)
CCJumpBy *jump = [CCJumpBy actionWithDuration:3 position:CGPointZero height:size.height / 3 jumps:2];
CCRepeatForever *repeatJump = [CCRepeatForever actionWithAction:jump];
[jumpL runAction: repeatJump];
//3、旋转字体,angle:360是顺时针旋转,如果是-360就是逆时针旋转
CCRotateBy *rotate = [CCRotateBy actionWithDuration:2 angle:360];
CCRepeatForever *repeatBounce = [CCRepeatForever actionWithAction:rotate];
[rotateL runAction:repeatBounce];
//4、闪烁出现,10秒中闪20次
CCBlink *blink = [CCBlink actionWithDuration:10 blinks:20];
CCRepeatForever *repeatBlink = [CCRepeatForever actionWithAction:blink];
[blinkL runAction:repeatBlink];
//5、悬挂下落动作
CGPoint hangInTherePosition = CGPointMake(hangL.position.x, size.height - [hangL texture].contentSize.height);
CGPoint belowScreenPosition = CGPointMake(hangL.position.x, -[hangL texture].contentSize.height);
CCMoveTo *moveHang = [CCMoveTo actionWithDuration:3 position:hangInTherePosition];
CCEaseElasticOut *easeHang = [CCEaseElasticOut actionWithAction:moveHang];
CCMoveTo *moveEnd = [CCMoveTo actionWithDuration:2 position:belowScreenPosition];
CCEaseBackInOut *easeEnd = [CCEaseBackInOut actionWithAction:moveEnd];
CCSequence *hangsequence = [CCSequence actions:easeHang,easeEnd, nil];
CCRepeatForever *hangRepeat = [CCRepeatForever actionWithAction:hangsequence];
[hangL runAction:hangRepeat];
//6、放大缩小
CCScaleTo *scaleBy1 = [CCScaleTo actionWithDuration:2 scale:2.0f];
CCScaleTo *scaleTo1 = [CCScaleTo actionWithDuration:2 scale:1.0f];
CCSequence *scaleSequence = [CCSequence actions:scaleBy1, scaleTo1, nil];
CCRepeatForever *repeatScale = [CCRepeatForever actionWithAction:scaleSequence];
[scaleL runAction:repeatScale];
//7、有变无,无变有
CCFadeIn *fadeIn = [CCFadeIn actionWithDuration:2];
CCFadeOut *fadeOut = [CCFadeOut actionWithDuration:2];
CCSequence *fadeSequence = [CCSequence actions:fadeIn,fadeOut,nil];
CCRepeatForever *repeatFade = [CCRepeatForever actionWithAction:fadeSequence];
[fadeL runAction:repeatFade];
分享到:
相关推荐
资源名称:Cocos2d-x实战:JS卷——Cocos2d-JS开发内容简介:本书是介绍Cocos2d-x游戏编程和开发技术书籍,介绍了使用Cocos2d-JS中核心类、瓦片地图、物理引擎、音乐音效、数据持久化、网络通信、性能优化、多平台...
cocos2d入门 cocos2d入门 cocos2d入门 cocos2d入门 cocos2d入门 cocos2d入门
该资源主要用于cocos2d-x中Value与json字符串的相互转换,提供从json文件读取为cocos2d::Value,cocos2d::Value写入到文件,cocos2d::Value转换为json字符串,json字符串转换为cocos2d::Value。json字符串转换成cocos...
【iOS-Cocos2d游戏开发】Cocos2d-iPhone动作Action-延时动作 http://blog.csdn.net/tt5267621/article/details/7625309
第1章 开始前的准备工作 1 第2章 你的第一款iPhone游戏:垂直射击游戏 38 第3章 Cocos2D核心类 69 第4章 Cocos2D中的动作、特效与动画 152 第5章 Cocos2D中的文本渲染系统 229 共19章
cocos2d-x-2.1.5
在使用cocos2d-x开发游戏的过程中,为了实现逻辑和显示相分离。 在下通宵了一个晚上,写出了该事件类。 谨记,该事件只能用于cocos2d-x中。 事件发送者需要继承EventDispatcher类 事件接收者需要继承EventHandle类...
cocos2d-x 地图双指缩放,单指拖动,双击自动放大
cocos2d-x游戏代码
Cocos2D-html5 2.1.4 实现鼠标控制物体旋转 需要Cocos2D-html5 2.1.4源码及XAMPP环境 相应文章链接:http://blog.csdn.net/johnhany/article/details/9298109 Cocos2D-html5 2.1.4源码下载:...
Cocos2D-X开发学习笔记-动作管理类的使用示例 教程地址:http://blog.csdn.net/yangyu20121224/article/details/10007849
cocos2d-x实战项目 01.cocos2d-x原理及环境配置.rar 03.cocostudio使用方法及UI控制.rar 04.XML文件读取与骨骼动画.rarcocos2d-x实战项目 01.cocos2d-x原理及环境配置.rar 03.cocostudio使用方法及UI控制.rar 04.XML...
Ray Wenderlich的《Cocos2d SimpleGame》,被认为是cocos2d的初学者最好的教程,这本书被Cocos2D-X团队从objective-c转化到了c++版,并发布在了github上。在此感谢Ray Wenderlich的慷慨相助。 源代码是在cocos2d-x ...
windows环境,一款很好用cocos2d粒子特效编辑器,里面有不少例子
【iOS-Cocos2d游戏开发】Cocos2d-iPhone动作Action-扩展动作 http://blog.csdn.net/tt5267621/article/details/7626450
Cocos2d-x实战 JS卷 Cocos2d-JS开发 PDF 电子书完整版本
cocos2d资料大全,里面有丰富的资源,游戏引擎是一种特殊的软件,它提供游戏开发时需要的常见功能;引擎会提供许多组件,使用这些组件能缩短开发时间,让游戏开发变得更简单;专业引擎通常会能比自制引擎表现出更好的...
Cocos2d-x实战
cocos2d的学习资料,一本比较经典的cocos2d开发书,适合cocos2d/cocos2d-x的入门
Cocos2d-x是移动跨平台开发最流行的游戏引擎,而本书是一本很全面的、比较‘接地气’的游戏开发教程。书中汇聚了热门手机游戏《捕鱼达人》开发的实战经验,作者从最基础的内容开始,逐步深入地介绍了Cocos2d-x的相关...