2011-04-01 41 views
1

我通过足球的约10个不同的图像,以使它看起来就像是旋转运行,但我是一个CCAnimation像这样做(cocos2d的):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

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

+0

我确实使用了CCSpriteFrameCache:NSString * bulletFrame = [NSString stringWithFormat:@“Football-%i.png”,i]; CCSpriteFrame * frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:bulletFrame]; [frames addObject:frame]; – mm24 2012-05-17 17:10:13

0

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

+0

感谢您的帮助! – Stephen 2011-04-01 19:48:28