Can you test for a down event on a Menu item?

Hi,

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?

Thanks in advance.

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

return true;
}
return false;
}

void CCMenu::ccTouchEnded(CCTouch touch, CCEvent event)
{
CCAssert(m_eState == kCCMenuStateTrackingTouch, “[Menu ccTouchEnded] — invalid state”);
if (m_pSelectedItem)
{
m_pSelectedItem~~>unselected;
// m_pSelectedItem~~>activate(); // disable it!
}
m_eState = kCCMenuStateWaiting;
}

And you can add more interfaces into the listener “SelectorProtocol” for CCMenuItem, reference to CCMenuItem::activate Hope this can help you.