I can not find anything on this topic. On all sites they write about the setSwallowTouches method, but is it only for EventListenerTouch ? I would be very grateful if you give a code snippet.
1 answer
Probably a very late answer, but still. To handle the mouse used EventListenerMouse; For example, we have an object of class Player, which is inherited from cocos2d :: Sprite. We announce in it:
using namespace cocos2d; // или можете писать в коде cocos2d::Event, cocos2d::MouseEvent и т.д. EventListenerMouse *mouseListener_; void onMouseDown(Event *event); //если нажата кнопка мыши void onMouseUp(Event *event); // если отжали кнопку мыши void onMouseMove(Event *event); // отслеживаем движение In the constructor of the Player class, install the "Listener"
mouseListener_ = EventListenerMouse::create(); mouseListener_->onMouseMove = CC_CALLBACK_1(Player::onMouseMove, this); mouseListener_->onMouseUp = CC_CALLBACK_1(Player::onMouseUp, this); mouseListener_->onMouseDown = CC_CALLBACK_1(Player::onMouseDown, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(mouseListener_, this); Further we write methods for our class. For example, to move the mouse (the function will automatically trigger when you move the cursor):
void Player::onMouseMove(Event *event) { EventMouse *eventMouse = (EventMouse*)event; //Например, каждый раз получаем координаты мыши и присваиваем временной переменной MouseCoordY auto MouseCoordY = eventMouse->getCursorY(); } More details can be found at http://amanita-studio.com/ru/articles/read/cocos2d-x-event-listener - It really helped me.
|