Hey all, I'm a little confused as to how to do this. I have a class (Spaceship) that is a subclass of CCSprite, or at least I want it to be. I am also using CCSpriteSheet (I know it was changed recently, but I'm using .99.4, so when I update I will change to the new name).
So, in my subclass, I tried this:
+(id)initSpaceShip {
//return [super spriteWithSpriteFrameName:@"Spaceship.png"]; //Although this worked, it returns a CCSprite, not a spaceship
return [[[self alloc] initWithSpaceShip] autorelease];
}
-(id)initWithSpaceShip {
if ( (self = [super spriteWithSpriteFrameName:@"Spaceship.png"]) ) {
//custom init
self.position = ccp(200, 50);
self.shipVelocity = 0;
}
return self;
}
However, I get a warning saying: "CCSprite may not respond to spriteWithSpriteFrameName:" And indeed it doesn't, the code crashes at that point. So then I did some reading, and found this, which says I should be overriding that one method. So I tried that:
-(id) initWithTexture:(CCTexture2D*)texture rect:(CGRect)rect
{
if( (self=[super initWithTexture:texture rect:rect]))
{
self.position = ccp(200, 50);
self.shipVelocity = 0;
}
return self;
}
//Then I create the ship like...
self.ship = [SpaceShip spriteWithSpriteFrameName:@"Spaceship.png"];
And while this works, it still creates a CCSprite, not a Spaceship object. So how am I supposed to create my subclass so it's a Spaceship object, and it is also created from the sprite sheet?
Thanks for your help, I really appreciate it!!