没有在cocos2d中显示精灵动画

时间:2011-03-15 11:42:42

标签: animation cocos2d-iphone sprite

我在sprite中创建动画。我在特定时期之后更改精灵并永远重复它。我已经引用了很多网站,格式如下:

-(id) init  
{  
    if( (self=[super init] )) 
    {   

        CCSpriteSheet *spriteSheet = [CCSpriteSheet   spriteSheetWithFile:@"apls.png" capacity:3]; 

        [[CCSpriteFrameCache sharedSpriteFrameCache]   addSpriteFramesWithFile:@"apls.plist"]; 

        CCSprite *sprite = [CCSprite spriteWithSpriteFrameName:@"apple2.png"]; 
        sprite.position = ccp(230,230);                     
        [spriteSheet addChild:sprite];  
        [self addChild:spriteSheet];  


        NSMutableArray *animFrames = [NSMutableArray array];  
        for(int i = 2; i < 5; i++)  
        {  

            CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] 
                        spriteFrameByName: [NSString stringWithFormat:@"apple%d.png",i]];  
            [animFrames addObject:frame];  

        }  

        CCAnimation *animation = [CCAnimation animationWithName:@"dance"      
                                delay:0.2f  frames:animFrames];  

        [sprite runAction:[CCRepeatForever actionWithAction: 
        [CCAnimate  actionWithAnimation:animation restoreOriginalFrame:NO] ]];  

    }  
    return self;  
}

这是相同的代码。但在模拟器上它没有显示任何东西。只是帧率不断变化 有什么我想念的吗?

提前谢谢。

1 个答案:

答案 0 :(得分:1)

试试这个。

NSMutableArray *animFrames = [NSMutableArray array];  
    for(int i = 2; i < 5; i++)  
    {  

        CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] 
                    spriteFrameByName: [NSString stringWithFormat:@"apple%d.png",i]];  
        [animFrames addObject:frame];  
    }

CCAnimation *animation = [CCAnimation frames:animFrames delay:0.2f]; 

[sprite runAction:[CCRepeatForever actionWithAction: [CCAnimate actionWithAnimation:animation restoreOriginalFrame:NO] ]];