c++ - Setting swipe event to a sprite -
i'm assinging swipe event cocos2dx sprite problem event assigned whole screen. want assigned single sprite. here code:
rect = sprite::create(); rect->settexturerect(rect(0, 0, 180, 80)); // ekranın y ekseninde ortası | visiblesize.height / 2 + origin.y rect->setposition(point(visiblesize.width / 2 + origin.x, visiblesize.height + 80)); auto grad = layergradient::create(color4b(255, 255, 38, 255), color4b(199, 173, 68, 255)); grad->changeheight(rect->getcontentsize().height); grad->changewidth(rect->getcontentsize().width); //grad->setposition(point(visiblesize.width / 2 + origin.x, visiblesize.height / 2 + origin.y)); //grad->addchild(rect); rect->addchild(grad); this->addchild(rect); auto listener = eventlistenertouchonebyone::create(); listener->ontouchbegan = cc_callback_2(gamescene::ontouchbegan, this); listener->ontouchmoved = cc_callback_2(gamescene::ontouchmoved, this); listener->ontouchended = cc_callback_2(gamescene::ontouchended, this); listener->ontouchcancelled = cc_callback_2(gamescene::ontouchcancelled, this); listener->setswallowtouches(true); this->geteventdispatcher()->addeventlistenerwithscenegraphpriority(listener, rect);
a touch event triggered when player touches screen. best way implement listener on sprite sub-classing it: http://www.cocos2d-x.org/wiki/how_to_subclass_sprite_and_add_event_listeners
you can later check collision of touch within sprite listener event (on touch began) , perform function
Comments
Post a Comment