1

I am creating animation in sprite.I am changing sprite after perticular period and repeating it forever.I have referred many site and the format is same as below:

-(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;  
}

this is the code for the same. But on simulator it is not showing anything. just frame rate keeps on changing.
Is there something which I am missing?

thanks in advance.

user392406
  • 1,323
  • 5
  • 28
  • 53
  • is your sprite displayed if you'll comment all the animation code ? – Andrew Mar 15 '11 at 12:14
  • yes, without animation it is showing other sprites CCSprite *p=[CCSprite spriteWithFile:@"apple1.png"]; p.position=ccp(230,230); [self addChild:p z:0 tag:1]; this code is displaying apple1 image but animation code is not working. – user392406 Mar 15 '11 at 12:21
  • There is frame animation example coming with cocos2d (in spriteTest example). Take a look there – Andrew Mar 15 '11 at 12:29
  • If possible can you plzz send me the link I am not finding it.. – user392406 Mar 15 '11 at 12:33
  • I have tried that example but the result is same. It is not showing anything except the frame rate..:( – user392406 Mar 15 '11 at 12:46
  • try to make a new animation frames and drag in your project.. may be it solves your problem –  Jun 08 '11 at 08:38

1 Answers1

1

Try this.

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] ]];

coldjacket
  • 26
  • 2