views:

9

answers:

0
+1  Q: 

cocos2d animate

I try create animation in my application written on cocos2d. I make it on this tutorial http://getsetgames.com/tag/ccanimation/ All work fine. But I write all code in my Engine class. Also I have class for object which I would like animate. And I have special class for create object. Now

I try next File which must have animation spritesheet. // GiftSprite.h

#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "LevelScene.h";

@interface GiftSprite : CCSprite {
...
    CCSpriteSheet *giftSpriteSheet;
}
...
@property (assign, readwrite) CCSpriteSheet *giftSpriteSheet;
...


@end 

File witch create GiftSprite and method addGift

-(void) addGift: (ccTime) time {
gift.giftSpriteSheet = [CCSpriteSheet spriteSheetWithFile:@"redGift.png"];// In this place I try retain.
gift = [GiftSprite spriteWithTexture:gift.giftSpriteSheet.texture rect:CGRectMake(0,0,30,30)];
}

And file which create Animation if some event catch.

NSLog(@"%@", gift.giftSpriteSheet);// in this place I see NULL
            CCAnimation *fallingShowAnimation = [CCAnimation animationWithName:@"fallingInSnow" delay:0.5f];
            for(int x=0;x<6;x++){
                CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:gift.giftSpriteSheet.texture rect:CGRectMake(x*30,0,30,30) offset:ccp(0,0)];
                [fallingShowAnimation addFrame:frame];
            }
            CCAnimate *giftAnimate = [CCAnimate actionWithAnimation:fallingShowAnimation];
            [gift runAction:giftAnimate];

And when I make it. on my animation I just see white square. How I can resolve this problem