c++ - cocos2d-x touch handling with layers -
i have problem cocos2d-x touch handler. have 2 classes. each class has 1 scene , 1 layer.i have sprites on both layers, , handle in same function. problem when create transition layer layer b , click on sprite, touch handler gets sprite layer a, need sprite layer b, click on layer b. far understood, problem in setpriority? please help me solve problem? thanks
carditem sprite
void carditem::addevents() { auto listener = cocos2d::eventlistenertouchonebyone::create(); listener->setswallowtouches(true); listener->ontouchbegan = [&](cocos2d::touch* touch, cocos2d::event* event) { cocos2d::vec2 p = touch->getlocation(); cocos2d::rect rect = this->getboundingbox(); if(rect.containspoint(p)) { homecoming true; // indicate have consumed it. } homecoming false; // did not consume event, pass thru. }; listener->ontouchended = [=](cocos2d::touch* touch, cocos2d::event* event) { //i have here code }; cocos2d::director::getinstance()->geteventdispatcher()->addeventlistenerwithfixedpriority(listener, 30); } void carditem::touchevent(cocos2d::touch* touch, cocos2d::vec2 _point) { auto *pnode = this->getparent(); // here "pnode" gets layer }
that's how alter scenes beetween layer , b
void gameboardlayer::showgameboardcomputer() { pgameboardcomputerscene = gameboardcomputerscene::create(); auto pgameboardcomputerlayer = pgameboardcomputerscene->getlayer(); director::getinstance()->pushscene(pgameboardcomputerscene); } void gameboardcomputerlayer::gameboardcomputeritembackcallback(ref* psender) { director::getinstance()->popscene(); }
so when click on sprite no matter layer is, clicks on layer through layer b
c++ touch cocos2d-x layer cocos2d-x-3.0
No comments:
Post a Comment