'NSInvalidArgumentException', reason: '-[HelloWorldLayer starGame:]: unrecognized selector sent to instance 0x96764d0' [closed]

StackOverflow https://stackoverflow.com/questions/16411881

  •  14-04-2022
  •  | 
  •  

Question

I have button in helloworld layer. When i click the button i need to replace gmaelayer scene. But when i click button i got error.

code:

 - (id) init
    {
        if ((self = [super initWithColor:ccc4(255,255,255,255)])) {

          CGSize winSize0 = [[CCDirector sharedDirector] winSize];


            CCMenuItem *starMenuItem = [CCMenuItemImage
                                        itemFromNormalImage:@"player.png" selectedImage:@"player.png"
                                        target:self selector:@selector(starGame:)];

            CCMenu *starMenu = [CCMenu menuWithItems:starMenuItem,nil];

            starMenu.position = ccp(winSize0.width/2  , 25);
            [starMenu alignItemsHorizontally];
            [self addChild:starMenu];
}
     return self;
    }


    -(void)startGame:(id)sender{

       [[CCDirector sharedDirector] replaceScene:[GameLayer scene]];


    }
Was it helpful?

Solution

You selector method is wrong.

CCMenuItem *starMenuItem = [CCMenuItemImage
                                        itemFromNormalImage:@"player.png" selectedImage:@"player.png"
                                        target:self selector:@selector(starGame:)];

Instead of

CCMenuItem *starMenuItem = [CCMenuItemImage
                                        itemFromNormalImage:@"player.png" selectedImage:@"player.png"
                                        target:self selector:@selector(startGame:)];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top