Hi Riq,
I'll show the Enemy class only, since it's the same problem / behavior / issue with that and Coin. Here goes. Sorry for the long code snippet... i'll try to remove extraneous stuff where necessary.
Basic architecture: GameScene -> calls Enemy class where all the chipmunk and sprite logic is. Gamescene has a factory method that creates an array of Enemies.
In my Enemy.m file.:
Note that 2 "weird" things I'm doing is passing *space and the _spriteSheet as parameters in the init.
- space is used for chipmunk ops inside Enemy (although I think I heard I can make it extern form the gamescene class and avoid passing it in).
- _spriteSheet: As for _spriteSheet: i'm not using it, since it yields a blank sprite, even though the pointers are pointing to the same address in memory
Now the code which works. If I were to uncomment the line indicated with **** and subsequently remove the ensuing 5 lines, it doesn't work.
-(id)initWithPositioninLayer:(CCLayer *)layer inSpace:(cpSpace *)space AtX:(float)x y:(float)y spriteSheet:(CCSpriteSheet *)_spriteSheet {
self = [super init];
if (self != nil) {
mySpace = space;
self.myLayer = layer;
... bunch of vars deleted.......
**** //self.spriteSheet = _spriteSheet; //<---- COMMENTED THIS OUT SINCE IT WASN'T WORKING
//******INSTEAD I ADDED THE SAME SPRITE SHEET DECLARATION FROM GAMESCENE (WHICH SEEMS REDUNDANT)
self.spriteSheet = [CCSpriteSheet spriteSheetWithFile:@"texture.png" capacity:50];
[self.myLayer addChild:self.spriteSheet];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"texture.plist"];
//**** END SPRITESHEET *************
self = [super initWithCPShape:[self makeEnemy]];
}
return self;
}
-(cpShape *)makeEnemy {
//CCSprite *sprite = [CCSprite spriteWithFile:@"enemy.png"]; //old line prior to using CCSPriteSheet
CCSprite *sprite = [CCSprite spriteWithSpriteFrameName:@"enemy.png"];
[self.spriteSheet addChild:sprite]; //add it to the spritesheet
return [self createShapeWithSprite:sprite];
}
Thanks for the help.