cocos2d的基本动作
//定义一个图片精灵
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]];
相关新闻>>
- 发表评论
-
- 最新评论 更多>>