I noticed for menu items that the callback function is called on the event that a button has been released. Is there a way to setup a callback for the button down event? Or is there a way to test if a user is holding a button down?
There’s no standard interface for this. But you can easily hack the engine internal to do it.
Take a look at cocos2d-x/cocos2dx/platform/CCMenu_mobile.cpp, move m_pSelectedItem~~>activate; from CCMenu::ccTouchEnded to CCMenu::ccTouchBegan, just like this
<pre>
bool CCMenu::ccTouchBegan
{
if
{
return false;
}
m_pSelectedItem = this~~>itemForTouch(touch);
if (m_pSelectedItem)
{
m_eState = kCCMenuStateTrackingTouch;
m_pSelectedItem~~>selected;
m_pSelectedItem~~>activate(); // call active here