[osx] button won't work!

Hi All!

I’m new to Cocos2d-x (congrats on an awesome framework)

I’m having a hard time getting a button to work…
so far this is my code:

@ CCSize frame = CCDirector::sharedDirector()>getWinSize;
float centerX = frame.width / 2.0f;
float centerY = frame.height / 2.0f;
CCMenuItemImage* button = CCMenuItemImage::create );
button
>setPosition( ccp( centerX, centerY + 60.0f ) );

CCMenu *menu = CCMenu::create( button, NULL );
menu->setPosition( ccp( 0.0f, 0.0f ) );
addChild( menu );
setTouchEnabled( true );@

This code is in the init method of a CCLayer.
The button appears on screen correctly but it won’t respond to being pressed with the mouse. It doesn’t change to the “active” image and the callback does not get called.
Can anyone help me?

Thanks

You don’t use ‘SEL_MenuHandler’ here. Insted you should use ‘menu_selector’ macro.

So yout line becomes :

 CCMenuItemImage* button = CCMenuItemImage::create( "button_release.png", "button_press.png", this, menu_selector( IntroScene::buttonPress ) ); 

Pawel Lopusinski wrote:

You don’t use ‘SEL_MenuHandler’ here. Insted you should use ‘menu_selector’ macro.
>
So yout line becomes :
[…]

Hi, thanks for your reply…

I tried to change that line but it still doesn’t work… :I was looking at the “menu_selector” macro definition
#define menu_selector(_SELECTOR) (SEL_MenuHandler)(&_SELECTOR)
and its just a wrapper around a SEL_MenuHandler, so it should be exactly the same as using SEL_MenuHandler directly

Yeah you are right, sorry.

Do you override touch handlers in your class? Maybe you simply swallow the touch in your layer and it does not get passed to menu.

Pawel Lopusinski wrote:

Yeah you are right, sorry.
>
Do you override touch handlers in your class? Maybe you simply swallow the touch in your layer and it does not get passed to menu.

No… :I made my own “Button” class and got it working by checking manually it the touch point is inside the Button… but it would be great to understand what is going on here….