NJUHOBBY
NJUHOBBY

Reputation: 850

CCMenuItemImage builded with cocosbuilder can't call my methods

So I built a CCMenuItemImage with cocosbuilder in my cocosbuilder project and use it later in my project. However, the responding method is never called.enter image description here

enter image description here

Upvotes: 1

Views: 836

Answers (3)

fith
fith

Reputation: 101

Go up to the Document menu and make sure "JavaScript Controlled" is unchecked.

I was having a really hard time with this. CCBControlButtons called their selectors, but CCMenuItemImages didn't. Changed that setting and it's working now.

Upvotes: 2

romin
romin

Reputation: 159

well, that's happened to me too...

the solution is first, u have to press enter after u've typed the selector field..

secondly, u have to publish (I do more than once).

for your info.... when u saved cocosbuilder project (cmd + s), u will not save the entire project... u'll only save current scene....

so, just in case u should save and publish on every scene u worry..

last tip (i don't know the different though), I chose document root (not owner ) :D

may this tips help you bro!

Upvotes: 0

Sylvan
Sylvan

Reputation: 536

You didn't provide very much information that allows us to help. However, I recently did the same thing with my app so perhaps I can give you some ideas on where to look. First, is the CCMenu its own root node (separate file) or is it a child of a CCLayer in your CocosBuilder file?

In the first scenario, the CCMenu (and CCMenuItemImage) is a separate node file, then you would link it to your game layer code with the statement:

CCMenu *menu = [CCBReader nodeGraphFromFile:@"filename.ccbi" owner:self];

Then in the Cocosbuilder program, where you type in the name of the method the CCMenuItemImage links to, make sure you select "Owner" instead of "Document root".

The second scenario is where your Cocosbuilder file is a CCLayer and the CCMenu is a child of that layer, which might be a more likely scenario. If you successfully loaded your ccb file with

CCScene *scene = [CCBReader sceneWithNodeGraphFromFile:@"filename.ccbi"]; (might need to double-check that one, I am not at my XCode)

Then, in Cocosbuilder when you type in your CCMenuItemImage method name, select "Document Root" to link this to your code.

Then in your game layer's code, you should have the same method as you typed into Cocosbuilder. So if your game layer's method is:

-(void)pressedButton:(id)sender {
   CCLOG(@"Button pressed!");
}

Then you need to have the same method

pressedButton:

linked to that button in Cocosbuilder.

Hope this helps.

Upvotes: 0

Related Questions