Я получаю это исключение, когда пытаюсь создать новый слой.Итак, в основном у меня есть стандартный шаблон cocos2d, я просто удалил класс HelloWorldLayer и создал новый класс под названием GameScene, где я определил +scene
метод, init
и dealloc
методы
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
В моем appDelegate вместо старого слоя создайте новый из GameScene
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
…
// Run the intro Scene
[[CCDirector sharedDirector] runWithScene: [GameScene scene]];
}
Вывод на консоль показывает:
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'