Failed to set selector block for CCButton on a Layer

151 views Asked by At

So I'm using sprite builder, objective-c and Xcode. In sprite builder I created a layer that looks like this:

Where the continue button is a CCButton with selector "continueBlock"

and then in code, I add it to the content node of the scene where I want it to appear. I wanted to give it a sort of "pop-up" window effect when the block (level) is completed and then when continue was clicked it would be hidden again.

The problem is when I load it from the CCBReader I get a message saying "Failed to set selector/target block for "continueBlock""

I'm not sure what I'm doing wrong since I'm writing the "continueBlock" method in the class of the scene where I loaded the layer in the first place.

@implementation SceneGeneral{
    CCNode *__contentNode;
    CCNode *nextBlock;
}

-(void)didLoadFromCCB{
    self.userInteractionEnabled=TRUE;
    nextBlock = [CCBReader load: @"NextBlock"];
    [__contentNode addChild: nextBlock];
    nextBlock.visible=NO;
}

-(void)continueBlock{
    nextBlock.visible=NO;}
-(void)someMethod{
   if(some condition){
      nextBlock.visible=YES;
      // i know that this method is working because the layer does pop up when the condition is met.}
}

when the layer pops up on the desired scene

1

There are 1 answers

0
Pontus Armini On BEST ANSWER

A possible solution would be to set your button target to 'Owner' (instead of 'Document root') in the 'Item code connections' tab on the right hand side in Spritebuilder.

Then, load your popup scene with the load:owner method of CCBReader, like so:

nextBlock = [CCBReader load: @"NextBlock" owner:self];

This should do the trick :)