Barling
November 19, 2011, 11:30am
#1
I’m using a menu button for one of my game buttons.
The button is supposed to apply a force to my player when it is pushed (basically just run a function via a callback).
The thing though is…it only works after I release it.
How do I make it so, it only works right after I press it?
@
pCloseItem = CCMenuItemImage::itemFromNormalImage(
“spr__released.png”,
“spr_pressed.png”,
this,
menu_selector(HelloWorld::jumpCallback) );
// create menu, it’s an autorelease object
pMenu = CCMenu::menuWithItems(pCloseItem, NULL);
pMenu~~>setPosition;
this~~>addChild(pMenu, 1); @
Try this, create a sub-class and implement the selected* and/or unselected()* methods.
Barling
November 20, 2011, 12:56pm
#3
I derived it…but nothing happens when I click it?
http://codepad.org/O4SpKLGM
Dany0
November 20, 2011, 3:34pm
#4
CCLog never outputs me anything, on linux and android. I just quickly throw up a dirty label usually.
Make sure that you’re creating a Button, not a CCMenuItem.
Button::itemFromNormalImage(…) will not return a Button unless you override it to create a Button object.
Button* item = Button::itemFromNormalImage(…);
//This won’t work if you did not override the method to return a Button* instead
CCMenuItemImage* item = Button::itemFromNormalImage(…);
CCMenuItemImage::selected() and CCMenuItemImage::unselected() does nothing.