@FabrizioV wrote:
Hi guys,
I'm handling the touch events in my layer in the usual way as follows:
auto eventListener = EventListenerTouchOneByOne::create(); eventListener->onTouchBegan = CC_CALLBACK_2(xWordsLayer::onTouchBegan, this); eventListener->onTouchMoved = CC_CALLBACK_2(xWordsLayer::onTouchMoved, this); eventListener->onTouchEnded = CC_CALLBACK_2(xWordsLayer::onTouchEnded, this); this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(eventListener, this);
Now everything seems to be working fine. Then I tried to add a "Restart" button at the top of the screen, as follows:
auto size = Director::getInstance()->getWinSize(); auto mi1 = cocos2d::ui::Button::create(); mi1->setTouchEnabled(true); mi1->setTitleText("Restart"); mi1->setTitleFontSize(16); mi1->setAnchorPoint(Vec2(1,1)); mi1->setPosition(Vec2(size.width, size.height)); mi1->addTouchEventListener(CC_CALLBACK_2(xWordsLayer::askExit, this)); mi1->setTitleFontName("fonts/arial.ttf"); addChild(mi1);
Now if I do that, the button responds correcty, but the touch events associated to the layer are no longer responding. Another weird aspect is that when I run the app on the simulator, there are cases (apparently random) where the touch event respond - however most of the time they don't.
Could anyone please help me understand what am I doing wrong?Thanks!
Posts: 1
Participants: 1