I am prepared for many places that tell me that I should not inherit the CCSprite class, but simply add a sprite to my class as a member variable.
Here's what I did: Created a CCNode class, Added the CCSprite variable to my node class Initialized my sprite and added it as a child to my node.
Now I have CCLayer where I want to draw these sprites, but when I add my node as a child, nothing is drawn. If I add sprite nodes as a child, not a node, it will draw.
My question is, is there a way to make my sprites draw from adding node as a child of the layer or does it add sprites only?
I am new to Objective-c and iPhone dev, so any help would be greatly appreciated.
Edit Here is my CCNode class - animalSprite - my CCSprite.
@implementation Animal
@synthesize animalSprite = _animalSprite;
-(Animal *) initWithFile:(NSString *)texture position:(CGPoint) position
{
self.animalSprite = [CCSprite spriteWithFile:texture];
self.animalSprite.position = position;
self.animalSprite.scale = 0.25f;
[self addChild:self.animalSprite];
return self;
}
-(void) dealloc{
[super dealloc];
}
@end
Now in my CCLayer class, I have a level variable that contains a list of my nodes.
Level *level = [LoadLevel loadLevel];
for (Animal *animal in level.animals)
{
[self addChild:animal];
}
Change I create node objects and then add them to an array of class classes as follows.
Animal *animal = [[[Animal alloc] initWithFile:animalFileName position:position] autorelease];
[level.animals addObject:animal];
source
share