Stephen
Stephen

Reputation: 499

CCAnimation (Cocos2d)

I am running through about 10 different images of a football in order to make it look like it is spinning, and I am doing it with a CCAnimation Like so:

// 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];

So my question is when I collide with another object is there a way to slowly have the football stop spinning?

Upvotes: 1

Views: 5396

Answers (2)

Ali1S232
Ali1S232

Reputation: 3411

you can also change the delay of the current animation and increase it until n frames and the deactivate animate action

Upvotes: 2

Michael Behan
Michael Behan

Reputation: 3443

Create a new CCAnimation that is the ball slowing to a stop, when you detect the collision cancel the current animation action and run the other one.

Upvotes: 0

Related Questions