Mikayil Abdullayev
Mikayil Abdullayev

Reputation: 12366

Can't get an instance of an inherited class

I'm working with Cocos2D and I've made a very simple class that inherits from CCSprite. I have the following class method:

+(id)carWithFile:(NSString *)fileName{
Car *car= (Car*)[CCSprite spriteWithFile:fileName];
car.anchorPoint=ccp(0,0);
    NSLog(@"%@",[car class]);//Here I get CCSprite in the console
return car;
}

But to my surprise, I still get a CCSprite instance when I call this method. Even when I check in the method itself, the class of the newly created object is CCSprite instead of Car. What am I missing?

Upvotes: 0

Views: 44

Answers (1)

Pfitz
Pfitz

Reputation: 7344

If it is a subclass from car you can use

[Car spriteWithFile:fileName];

Upvotes: 2

Related Questions