I’m trying to initialize a scene in cocos2d (version 0.99.5) and want to pass in a parameter. In this case, the parameter is an int value corresponding to the level number. The scene class itself is a subclass of CCLayer, and I’m initializing it with the node class method:
GameScene *scene = [GameScene node]; //GameScene subclass of CCLayer
I have a custom init method that takes the variable “level”, as follows:
- (id) initWithGameLevel:(int)level {
if ((self = [super init])){
// etc
}
}
Just wondering: am I way off base in my approach in creating my own initWithX method, and how I would initialize the scene with the level integer?
Add this method to your subclass
and instead of
write