cocos2d的基本动作

来源:未知 责任编辑:智问网络 发表时间:2013-11-04 19:43 点击:

//定义一个图片精灵
CCSprite *sprite = [CCSprite spriteWithFile:@"1.jpg"];
CGSize s = [[CCDirector sharedDirector] winSize];
CGPoint p = ccp(s.width/2, 50);
//实现各种动作
[sprite runAction:[CCMoveTo actionWithDuration:1.0 position:p]];//移动到指定位置
[sprite runAction:[CCMoveBy actionWithDuration:1.0 position:ccp(20, 20)]];//运动到指定的x,y增量的位置
[sprite runAction:[CCScaleBy actionWithDuration:1.5 scale:1.1]];//放大
[sprite runAction:[CCRotateBy actionWithDuration:1.5 angle:60]];//旋转60度
[sprite runAction:[CCTintBy actionWithDuration:1.0 red:200 green:0 blue:0]];//变颜色
//连续动作  
id ac0 = [sprite runAction:[CCPlace actionWithPosition:p]];
id ac1 = [CCMoveTo actionWithDuration:2 position:ccp(s.width - 50, s.height - 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];   
[sprite runAction:[CCSequence actions:ac0,ac1,ac2,ac3,ac4, nil]];
//连续和并发动作一起   
sprite.rotation = 0;
[sprite setPosition:p];
id ac1 = [CCMoveTo actionWithDuration:2 position:ccp(s.width - 50, s.height - 50)];
id ac2 = [CCRotateTo actionWithDuration:2 angle:90];
id ac3 = [CCScaleTo actionWithDuration:1 scale:3];
id ac4 = [CCScaleBy actionWithDuration:1 scale:0.5];
id seq = [CCSequence actions:ac3, ac4, nil];
[sprite runAction:[CCSpawn actions:ac1, ac2, seq, nil]];
//重复一系列动作n次   
sprite.rotation = 0;
[sprite setPosition:p];
// 创建劢作序列
id ac1 = [CCMoveTo actionWithDuration:2 position:ccp(s.width - 50, s.height - 50)];
id ac2 = [CCJumpBy actionWithDuration:2 position:ccp(-400, -200) height:30 jumps:5];
id ac3 = [CCJumpBy actionWithDuration:2 position:ccp(s.width/2, 0) height:20 jumps:3];
id seq = [CCSequence actions:ac1, ac2, ac3, nil];
// 重复运行上述劢作序列 3 次。
[sprite runAction:[CCRepeat actionWithAction:seq times:3]];
   
//反动作 reverse
sprite.rotation = 0;
[sprite setPosition:p];
id ac1 = [CCMoveBy actionWithDuration:2 position:ccp(190,220)];
id ac2 = [ac1 reverse];
[sprite runAction:[CCRepeat actionWithAction:[CCSequence actions:ac1, ac2,nil] times:2]];

//增加时间间歇
id ac1 = [CCMoveBy actionWithDuration:2 position:ccp(100, 100)];
id ac2 = [ac1 reverse];
// 实现一个等待间歇
[sprite runAction:[CCSequence actions:ac1, [CCDelayTime actionWithDuration:2], ac2, nil]];


 

    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    用户名: 验证码:点击我更换图片
    最新评论 更多>>

    推荐热点

    • cocos2d-x学习笔记(19)--label 、label atlas
    • cocos2d-x学习笔记(23)--地图的使用3--CCTMXLayer
    • Cocos2d-x学习(一):HelloWorld
    • cocos2dx在xcode下开发,编译到android上(2)
    • cocos2d 设置屏幕默认方向
    • Cocos2d-x 2.0 之 Actions “三板斧” 之一
    • cocos2d-x学习笔记(22)--地图的使用2(TMX) --Z-Order、AnchorPoi
    • cocos2d-x学习笔记(18)--游戏打包(windows平台)
    • cocos2d-x学习笔记(16)--spritesheet(精灵表单)
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1