2011-04-01 59 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

相關問題