Search code examples
iphonexcodeselectorscenekobold2d

No known class method for selector scene?


Possible Duplicate:
Error “No known class method for selector 'Hello:'” in custom-made framework

I am creating a Main menu for my game here It does not compile but i do not understand why

//  Main Menu.m
//
//
//

#import "MainMenu.h"
#import "CCTouchDispatcher.h"
#import "Instructions.h"

CCSprite *seeker1;
CCSprite *cocosGuy;

@implementation MainMenu


+ (CCScene *) scene
{
    CCScene * scene = [CCScene node]; // scene is an autorelease object
    MainMenu * layer =  [MainMenu node]; // later is an autorelease object
    [scene addChild: layer]; // add layer as a child to scene
    return scene; // return the scene
}

- (id) init
{
    if ( ( self = [super init] ) )
    {
        [ self setUpMenus ];
    }
    return self;
}

- (void) setUpMenus
{

    // create menu items

    CCMenuItemImage * startButton = [CCMenuItemImage itemFromNormalImage:@"startbutton.png"
                                                           selectedImage:@"startbutton_selected.png"
                                                                  target: self
                                                                selector: @selector (doSomethingOne:)];


    CCMenuItemImage * instructionsButton = [CCMenuItemImage itemFromNormalImage:@"instructionsbutton.png"
                                                                  selectedImage:@"instructionbutton_selected.png"
                                                                         target: self
                                                                       selector: @selector(doSomethingTwo:)];


    CCMenuItemImage * unlockList = [CCMenuItemImage itemFromNormalImage: @"unlocklist.png"
                                                          selectedImage:@"unlocklist_selected.png"
                                                                 target: self
                                                               selector: @selector(doSomethingThree:)];

    // create the menu and add the items to it
    CCMenu * myMenu = [CCMenu menuWithItems: startButton, instructionsButton, unlockList,nil];


    // arrange the items vertically
    [myMenu alignItemsVertically];


    // add the menu to the scene
    [self addChild:myMenu];

}


- (void) doSomethingOne: (CCMenuItem *) menuItem
{


}

- (void) doSomethingTwo: (CCMenuItem  *) menuItem
{
    [[CCDirector sharedDirector] replaceScene:
     [CCTransitionFade transitionWithDuration:0.5f scene:[Instructions scene] ]];
}

- (void) doSomethingThree: (CCMenuItem  *) menuItem
{

}


@end

Why do I get the error that there is No known class method for the selector scene? regarding doSomethingTwo. Do I have to import something in the .h file? or an implementation? Thank you for any help you can provide me.


Solution

  • Does the Instructions class implement this selector?

    +(id) scene
    {
       id scene = [CCScene node];
       return scene;
    }
    

    And does the Instruction class' interface declare this selector so other classes can reference it?

    @interface Instructions : CCLayer
    {
    }
    
    +(id) scene;
    
    @end
    

    You need both.