Animation 不在cocos2d中显示精灵动画

Animation 不在cocos2d中显示精灵动画,animation,cocos2d-iphone,sprite,Animation,Cocos2d Iphone,Sprite,我正在用sprite创建动画。我在特定的时间段后更改sprite并永远重复它。我参考了许多网站,格式如下所示: -(id) init { if( (self=[super init] )) { CCSpriteSheet *spriteSheet = [CCSpriteSheet spriteSheetWithFile:@"apls.png" capacity:3]; [[CCSpriteFrameCache shared

我正在用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;  
}
-(id)init
{  
if((self=[super init]))
{   
CCSpriteSheet*spriteSheet=[CCSpriteSheet spriteSheetWithFile:@“apls.png”容量:3];
[[CCSpriteFrameCache sharedSpriteFrameCache]addSpriteFramesWithFile:@“apls.plist”];
CCSprite*sprite=[CCSprite spritewithpriteframename:@“apple2.png”];
sprite.position=ccp(230230);
[spriteSheet addChild:sprite];
[自添加子项:精灵表];
NSMutableArray*animFrames=[NSMutableArray];
对于(int i=2;i<5;i++)
{  
CCSpriteFrame*frame=[[CCSPRITEFRAMECHAREDSPRITFRAMECHARE]
spriteFrameByName:[NSString stringWithFormat:@“apple%d.png”,i]];
[动画帧添加对象:帧];
}  
cAnimation*动画=[cAnimation animation With Name:@“舞蹈”
延迟:0.2f帧:帧];
[sprite runAction:[CCRepeatForever actionWithAction:
[cAnimate actionWithAnimation:animation restoreOriginalFrame:NO]];
}  
回归自我;
}
这是相同的代码。但在模拟器上它并没有显示任何东西。只是帧速率一直在变化。
有什么东西我遗漏了吗

提前谢谢

试试这个

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]; 
NSMutableArray*animFrames=[NSMutableArray];
对于(int i=2;i<5;i++)
{  
CCSpriteFrame*frame=[[CCSPRITEFRAMECHAREDSPRITFRAMECHARE]
spriteFrameByName:[NSString stringWithFormat:@“apple%d.png”,i]];
[动画帧添加对象:帧];
}
c动画*动画=[c动画帧:动画帧延迟:0.2f];
[sprite runAction:[CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:animation Restore OriginalFrame:NO]]

试试这个

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]; 
NSMutableArray*animFrames=[NSMutableArray];
对于(int i=2;i<5;i++)
{  
CCSpriteFrame*frame=[[CCSPRITEFRAMECHAREDSPRITFRAMECHARE]
spriteFrameByName:[NSString stringWithFormat:@“apple%d.png”,i]];
[动画帧添加对象:帧];
}
c动画*动画=[c动画帧:动画帧延迟:0.2f];

[sprite runAction:[CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:animation Restore OriginalFrame:NO]]

如果要注释所有动画代码,是否会显示精灵?是的,如果没有动画,则会显示其他精灵CCSprite*p=[CCSprite spriteWithFile:@“apple1.png”];p.位置=ccp(230230);[self addChild:pz:0标记:1];此代码正在显示apple1图像,但动画代码不起作用。cocos2d附带了一个帧动画示例(在spriteTest示例中)。看一看,如果可能的话,你能给我发一个链接吗?我找不到。我试过这个例子,但结果是一样的。它不显示除帧速率以外的任何内容。:(如果您要注释所有动画代码,是否显示您的精灵?是的,没有动画,它显示其他精灵CCSprite*p=[CCSprite spriteWithFile:@“apple1.png”];p.position=ccp(230230);[self addChild:pz:0标记:1];此代码正在显示apple1图像,但动画代码不起作用。cocos2d附带了一个帧动画示例(在spriteTest示例中)。请查看该示例。如果可能,请将链接发送给我,我找不到该链接。我已尝试过该示例,但结果相同。除了帧速率之外,该示例不显示任何内容..:(