iphone - Cocos2D: Subclassing sprite and animation as CCLayer is giving me trouble -


i started experimenting cocos2d tiled, , had player sprite , actions coded within cclayer along else. before continuing on, wanted subclass player cclayer, hope correct.

my header , main code follows:

heroclass.h

#import <foundation/foundation.h> #import "cocos2d.h"  @interface heroclass : cclayer {     ccsprite *_hero;     ccaction *_herospriteflyaction;  }  @property(nonatomic, retain) ccsprite *hero; @property(nonatomic, retain) ccaction *herospriteflyaction;  @end 

heroclass.m

#import "heroclass.h"  @implementation heroclass  @synthesize hero =_hero; @synthesize herospriteflyaction = _herospriteflyaction;  -(id) init{     self = [super init];     if (!self) {         return nil;     }      [[ccspriteframecache sharedspriteframecache] addspriteframeswithfile:@"herotestsheet.plist"];      ccspritebatchnode *herospritesheet = [ccspritebatchnode batchnodewithfile:@"herotestsheet.png"];      [self addchild:herospritesheet];      nsmutablearray *herospriteflyanimframes = [nsmutablearray array];     for(int = 1; <= 2; ++i) {         [herospriteflyanimframes addobject:          [[ccspriteframecache sharedspriteframecache] spriteframebyname:           [nsstring stringwithformat:@"heroframe%d.png", i]]];     }      ccanimation *herospriteflyanim = [ccanimation animationwithframes:herospriteflyanimframes delay:0.03f];      self = [ccsprite spritewithspriteframename:@"heroframe1.png"];        _herospriteflyaction = [ccrepeatforever actionwithaction:[ccanimate actionwithanimation:herospriteflyanim restoreoriginalframe:no]];     [self runaction:_herospriteflyaction];      [herospritesheet addchild:self];       return self; }  - (void) dealloc{     self.hero = nil;     self.herospriteflyaction = nil;     [super dealloc]; }  @end 

i think idea want achieve can access things in class properties in other files. code above gives no errors when build it, maybe didn't right. problem i'm having migration happening in cclayer class debugzonelayer, creates map , supposed add player sprite giving me errors.

in debugzonelayer.h imported heroclass.h , made pointer heroclass of hero sprite , gave property. no errors here may start of i'm going wrong:

#import "cocos2d.h" #import "heroclass.h" @class heroclass;  // debugzone layer @interface debugzonelayer : cclayer {      herocontrol *herocontrol;      heroclass *hero;          cctmxtiledmap *themap;     cctmxlayer *blockscollidable;     cctmxlayer *invisiblepropertieslayer;    }   @property(nonatomic, retain) ccsprite *hero; 

in debugzonelayer.m, when synthesize hero, gives error "type of property 'hero' not match type of ivar 'hero'

@synthesize hero; 

the rest of file gives me more errors related referencing hero, @ least that's starts.

edit (updated)

just wanted mention, since solved cleared major issues in heroclass.m causing crash:

#import "heroclass.h"  @implementation heroclass  @synthesize herosprite =_herosprite; @synthesize herospritesheet =_herospritesheet; @synthesize herospriteflyaction = _herospriteflyaction;  -(id) init{     self = [super init];     if (!self) {         return nil;     }      [[ccspriteframecache sharedspriteframecache] addspriteframeswithfile:@"herotestsheet.plist"];      _herospritesheet = [ccspritebatchnode batchnodewithfile:@"herotestsheet.png"];      //[self addchild:_herospritesheet];      nsmutablearray *herospriteflyanimframes = [nsmutablearray array];     for(int = 1; <= 2; ++i) {         [herospriteflyanimframes addobject:          [[ccspriteframecache sharedspriteframecache] spriteframebyname:           [nsstring stringwithformat:@"heroframe%d.png", i]]];     }      ccanimation *herospriteflyanim = [ccanimation animationwithframes:herospriteflyanimframes delay:0.03f];      _herosprite = [ccsprite spritewithspriteframename:@"heroframe1.png"];        _herospriteflyaction = [ccrepeatforever actionwithaction:[ccanimate actionwithanimation:herospriteflyanim restoreoriginalframe:no]];     [self runaction:_herospriteflyaction];      [_herospritesheet addchild:_herosprite];       return self; }  - (void) dealloc{     self.herosprite = nil;     self.herospritesheet = nil;     self.herospriteflyaction = nil;     [super dealloc]; }  @end 

trying changing property in debugzonelayer class from:

@property(nonatomic, retain) ccsprite *hero; 

to:

@property(nonatomic, retain) heroclass *hero; 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -