// 增加动画
// **缩放效果**
id actionScale1 = [CCScaleBy actionWithDuration:2];
id actionScale2 = [CCScaleBy actionWithDuration:2 scale:2.0f];
id actionScale3 = [CCScaleBy actionWithDuration:2 scaleX:3.0f scaleY:3.0f];
// CCScaleBy 为缩放动画,actionWithDuration为执行次数,scale为缩放的大小,正值为放大,负值为缩小,最后的scaleX,scaleY为在X,Y方向作缩放动作。
// **旋转效果**
id actionRotate1 = [CCRotateBy actionWithDuration:2];
id actionRotate2 = [CCRotateBy actionWithDuration:2 angle:180.0f];
//其他同上,只是增加了angle,旋转的角度。
// **跳动效果**
id actionJump1 = [CCJumpBy actionWithDuration:3];
id actionJump2 = [CCJumpBy actionWithDuration:3 position:ccp(s.width/10, 0) height:20 jumps:3];
// 其他同上,最后一个是在3秒内跳转到右下角,连续跳3次,每次高度为20
// **同时执行旋转和跳动效果**
id actionSpan = [CCSpawn actions:actionRotate2, actionJump2, nil];
//以上的动作基本是有相反的动作的,可以通过reverse来作。
id back = [actionSpan reverse];
// **定制动画顺序**
id actionSequence = [CCSequence actions:actionJump1,actionRotate1,actionScale1, nil];
// **执行动画循环**
id actionRepeat = [CCRepeat actionWithAction:back times:2];
// **执行动画永久循环**
id actionRepeatForever = [CCRepeatForever actionWithAction:actionSequence];
//runAction 运行动画,你想要那个效果直接替换上面的动画即可。
[sprite1 runAction:actionRepeat];
//还有在运行过程的快慢
[sprite2 runAction:[CCEaseIn actionWithAction:actionRepeat rate:2]];
// [sprite2 runAction:[CCEaseOut actionWithAction:actionRepeat rate:3]];
// [sprite2 runAction:[CCEaseInOut actionWithAction:actionRepeat rate:3]];
// [sprite2 runAction:[CCEaseSineIn actionWithAction:actionRepeat]];
// [sprite2 runAction:[CCEaseSineOut actionWithAction:actionRepeat]];
// [sprite2 runAction:[CCEaseSineInOut actionWithAction:actionRepeat]];
// [sprite2 runAction:[CCEaseExponentialIn actionWithAction:actionRepeat]];
// [sprite2 runAction:[CCEaseExponentialOut actionWithAction:actionRepeat]];
// [sprite2 runAction:[CCEaseExponentialInOut actionWithAction:actionRepeat]];
// [sprite2 runAction:[CCSpeed actionWithAction:actionRepeat speed:(CCRANDOM_0_1() * 5)]];
【iphone游戏开发】iphone-Cocos2d游戏开发之四:精灵实现缩放,旋转,跳动,移动等动画
最新推荐文章于 2022-03-06 22:10:46 发布