Cocos2d iphone C动画(Cocos2d)

Cocos2d iphone C动画(Cocos2d),cocos2d-iphone,Cocos2d Iphone,为了让足球看起来像是在旋转,我正在浏览大约10幅不同的足球图像,我用这样的动画来做: // 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 stringWithFor

为了让足球看起来像是在旋转,我正在浏览大约10幅不同的足球图像,我用这样的动画来做:

// 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];
//加载足球动画帧作为纹理,并创建精灵帧
frames=[[NSMutableArray alloc]initWithCapacity:3];
对于(int i=0;i<10;i++)
{
NSString*文件=[NSString stringWithFormat:@“Football%i.png”,i];
CCTexture2D*纹理=[[CCTextureCache sharedTextureCache]addImage:file];
CGSize texSize=texture.contentSize;
CGRect texRect=CGRectMake(0,0,texSize.width,texSize.height);
CCSpriteFrame*frame=[CCSpriteFrame frameWithTexture:texture rect:texRect];
[帧添加对象:帧];
}
CCAnimation*anim=[CCAnimation animation withframes:frames delay:0.03f];
//使用CCAnimate操作运行动画
CCAnimate*animate=[CCAnimate actionWithAnimation:anim];
CCRepeatForever*repeat=[CCRepeatForever actionWithAction:animate];
[自我运行:重复];

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

创建一个新的动画,让球慢慢停下来,当检测到碰撞时,取消当前动画动作并运行另一个。

您还可以更改当前动画的延迟,并将其增加到n帧,然后取消动画动作。

我确实使用了CCSpriteFrameCache:NSStringbulletFrame=[NSStringStringWithFormat:@“Football-%I.png”,I]; CCSpriteFrame frame=[[CCSpriteFrameCache sharedSpriteFrameCache]spriteFrameByName:bulletFrame];[帧添加对象:帧];