[self classmethod]
in super class and then use it child class
I'm making some iPhone game based on cocos2d.
In many games I've seen before, the scene restart when user's character die or gone.
It can be done simply but needs some handling if implement in each child class.
[[CCDirector sharedDirector] replacescene:[childclass scene]];
But if I could implement in parent class, it can be done by once. I guess.
So I tried [self scene]
in parent class, but it doesn't work.
How can I do this in parent class?
added in
@interface Parent : CCLayer {}
+(CCScene*)scene;
-(void)dead;
@end
@implementation Parent
...
+(CCScene*)scene {
CCScene *scene = [CCScene node];
// 'layer' is an autorelease object.
Parent *layer = [Parent node];
// add layer as a child to scene
[scene addChild: layer];
// return the scene
return scene;
}
...
-(void)dead {
// called after character death
[[CCDirector sharedDirector] replacescene:[self scene]]; //This makes a error "Parent may not respond to 'scene'"
}
@interface Child1 : Parent {}
+(CCScene*)scene;
@end
@implementation Parent
...
+(CCScene*)scene {
CCScene *scene = [CCScene node];
// 'layer' is an autorelease object.
Child *layer = [Child node];
// add layer as a child to scene
[scene addChild: layer];
// return the scene
return scene;
}
...
@end
I think Child1 doesn't need dead method implementation because it's child class of Parent but it doesn't work. And Child2, Child3...too.
It works when I move the dead method to Child1 and modify its self -> Child1
Please let me know, if u can't understand my question. thank u for reply.