CCAnimation(Cocos2d)

时间:2011-04-01 15:01:44

标签: cocos2d-iphone

我正在浏览足球的大约10个不同的图像,以使它看起来像旋转,我正在使用CCAnimation这样做:

// load the football's animation frames as textures and create a sprite frame
frames = [[NSMutableArray alloc]initWithCapacity:3];
for (int i = 0; i < 10; i++)
{
  NSString* file = [NSString stringWithFormat:@"Football%i.png", i];
  CCTexture2D* texture = [[CCTextureCache sharedTextureCache] addImage:file];
  CGSize texSize = texture.contentSize;
  CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);
  CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:texture rect:texRect];
  [frames addObject:frame];
}

CCAnimation* anim = [CCAnimation animationWithFrames:frames delay:0.03f];

// run the animation by using the CCAnimate action
CCAnimate* animate = [CCAnimate actionWithAnimation:anim];
CCRepeatForever* repeat = [CCRepeatForever actionWithAction:animate];
[self runAction:repeat];

所以我的问题是,当我与另一个物体发生碰撞时,有没有办法慢慢让足球停止旋转?

2 个答案:

答案 0 :(得分:2)

您还可以更改当前动画的延迟并将其增加到n帧并停用动画动作

答案 1 :(得分:0)

创建一个新的CCAnimation,当你检测到碰撞取消当前的动画动作并运行另一个动作时,球会减速停止。