I get this exception when i try to create a new layer. So , basically i have a standart cocos2d template , i just removed HelloWorldLayer class and created a new class called GameScene, were i defined +scene method , init and dealloc methods
GameScene.h
#import "cocos2d.h"
@interface GameScene : CCLayer {}
+(id) scene;
@end
GameScene.m
#import "GameScene.h"
@implementation GameScene
+(id) scene {
CCScene *scene = [CCScene node];
GameScene *layer = [GameScene node];
[scene addChild:layer];
return self;
}
-(id) init {
if ((self = [super init])) {
CCLOG(@"New GameScene");
}
return self;
}
-(void) dealloc {
[super dealloc];
}
@end
I my appDelegate , instead of old layer , create new one from GameScene
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
…
// Run the intro Scene
[[CCDirector sharedDirector] runWithScene: [GameScene scene]];
}
Console output shows :
2012-02-06 20:37:04.284 Doodle[3908:10a03] +[GameScene onEnter]: unrecognized selector sent to class 0x1098c4
2012-02-06 20:37:04.288 Doodle[3908:10a03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[GameScene onEnter]: unrecognized selector sent to class 0x1098c4'
I figure it out. Instead of returning an id type for method
+scene, it should be aCCScenevalue.I’m still confused of why
idis not working cause it can be every type , even CCScene type.