开发者

CCAnimation (Cocos2d)

开发者 https://www.devze.com 2023-02-21 17:15 出处:网络
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:

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 = [CCSp开发者_运维百科riteFrame 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?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消