mirror of https://github.com/axmolengine/axmol.git
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:
commit
e2f14635e8
|
@ -149,7 +149,6 @@ bool Menu::initWithArray(Array* pArrayOfItems)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// [self alignItemsVertically];
|
|
||||||
_selectedItem = NULL;
|
_selectedItem = NULL;
|
||||||
_state = Menu::State::WAITING;
|
_state = Menu::State::WAITING;
|
||||||
|
|
||||||
|
@ -157,6 +156,17 @@ bool Menu::initWithArray(Array* pArrayOfItems)
|
||||||
setCascadeColorEnabled(true);
|
setCascadeColorEnabled(true);
|
||||||
setCascadeOpacityEnabled(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 true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -184,16 +194,6 @@ void Menu::addChild(Node * child, int zOrder, int tag)
|
||||||
void Menu::onEnter()
|
void Menu::onEnter()
|
||||||
{
|
{
|
||||||
Layer::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()
|
void Menu::onExit()
|
||||||
|
|
|
@ -80,6 +80,15 @@ bool Control::init()
|
||||||
_dispatchTable = new Dictionary();
|
_dispatchTable = new Dictionary();
|
||||||
_dispatchTable->init();
|
_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;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -93,25 +102,6 @@ Control::~Control()
|
||||||
CC_SAFE_RELEASE(_dispatchTable);
|
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)
|
void Control::sendActionsForControlEvents(EventType controlEvents)
|
||||||
{
|
{
|
||||||
// For each control events
|
// For each control events
|
||||||
|
|
|
@ -182,17 +182,6 @@ public:
|
||||||
// Overrides
|
// Overrides
|
||||||
virtual bool isOpacityModifyRGB() const override;
|
virtual bool isOpacityModifyRGB() const override;
|
||||||
virtual void setOpacityModifyRGB(bool bOpacityModifyRGB) 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:
|
protected:
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue