Merge pull request #4065 from dumganhar/develop

closed #3104: Touch listener should be registered in Menu::initXXX and Control::init rather than onEnter.
This commit is contained in:
James Chen 2013-11-01 05:55:32 -07:00
commit e2f14635e8
3 changed files with 20 additions and 41 deletions

View File

@ -149,7 +149,6 @@ bool Menu::initWithArray(Array* pArrayOfItems)
}
}
// [self alignItemsVertically];
_selectedItem = NULL;
_state = Menu::State::WAITING;
@ -157,6 +156,17 @@ bool Menu::initWithArray(Array* pArrayOfItems)
setCascadeColorEnabled(true);
setCascadeOpacityEnabled(true);
auto touchListener = EventListenerTouchOneByOne::create();
touchListener->setSwallowTouches(true);
touchListener->onTouchBegan = CC_CALLBACK_2(Menu::onTouchBegan, this);
touchListener->onTouchMoved = CC_CALLBACK_2(Menu::onTouchMoved, this);
touchListener->onTouchEnded = CC_CALLBACK_2(Menu::onTouchEnded, this);
touchListener->onTouchCancelled = CC_CALLBACK_2(Menu::onTouchCancelled, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
return true;
}
return false;
@ -184,16 +194,6 @@ void Menu::addChild(Node * child, int zOrder, int tag)
void Menu::onEnter()
{
Layer::onEnter();
auto touchListener = EventListenerTouchOneByOne::create();
touchListener->setSwallowTouches(true);
touchListener->onTouchBegan = CC_CALLBACK_2(Menu::onTouchBegan, this);
touchListener->onTouchMoved = CC_CALLBACK_2(Menu::onTouchMoved, this);
touchListener->onTouchEnded = CC_CALLBACK_2(Menu::onTouchEnded, this);
touchListener->onTouchCancelled = CC_CALLBACK_2(Menu::onTouchCancelled, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
}
void Menu::onExit()

View File

@ -80,6 +80,15 @@ bool Control::init()
_dispatchTable = new Dictionary();
_dispatchTable->init();
auto dispatcher = Director::getInstance()->getEventDispatcher();
auto touchListener = EventListenerTouchOneByOne::create();
touchListener->onTouchBegan = CC_CALLBACK_2(Control::onTouchBegan, this);
touchListener->onTouchMoved = CC_CALLBACK_2(Control::onTouchMoved, this);
touchListener->onTouchEnded = CC_CALLBACK_2(Control::onTouchEnded, this);
touchListener->onTouchCancelled = CC_CALLBACK_2(Control::onTouchCancelled, this);
dispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
return true;
}
else
@ -93,25 +102,6 @@ Control::~Control()
CC_SAFE_RELEASE(_dispatchTable);
}
void Control::onEnter()
{
Layer::onEnter();
auto dispatcher = Director::getInstance()->getEventDispatcher();
auto touchListener = EventListenerTouchOneByOne::create();
touchListener->onTouchBegan = CC_CALLBACK_2(Control::onTouchBegan, this);
touchListener->onTouchMoved = CC_CALLBACK_2(Control::onTouchMoved, this);
touchListener->onTouchEnded = CC_CALLBACK_2(Control::onTouchEnded, this);
touchListener->onTouchCancelled = CC_CALLBACK_2(Control::onTouchCancelled, this);
dispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
}
void Control::onExit()
{
Layer::onExit();
}
void Control::sendActionsForControlEvents(EventType controlEvents)
{
// For each control events

View File

@ -182,17 +182,6 @@ public:
// Overrides
virtual bool isOpacityModifyRGB() const override;
virtual void setOpacityModifyRGB(bool bOpacityModifyRGB) override;
/**
* @js NA
* @lua NA
*/
virtual void onEnter() override;
/**
* @js NA
* @lua NA
*/
virtual void onExit() override;
// virtual void registerWithTouchDispatcher() override;
protected:
/**