#include <base/CCEventListenerMouse.h> #include <base/CCEvent.h>
void onMouseDown(cocos2d::Event* event); void onMouseUp(cocos2d::Event* event); void onMouseMove(cocos2d::Event* event); void onMouseScroll(cocos2d::Event* event);
auto mouseListener = EventListenerMouse::create(); mouseListener->onMouseMove = CC_CALLBACK_1(HelloWorld::onMouseMove, this); mouseListener->onMouseUp = CC_CALLBACK_1(HelloWorld::onMouseUp, this); mouseListener->onMouseDown = CC_CALLBACK_1(HelloWorld::onMouseDown, this); mouseListener->onMouseScroll = CC_CALLBACK_1(HelloWorld::onMouseScroll, this); this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(mouseListener, this);
void HelloWorld::onMouseDown(Event* event) { EventMouse* e = (EventMouse*)event; log("mouse down. key = %d (%g, %g)", e->getMouseButton(), e->getCursorX(), e->getCursorY()); } void HelloWorld::onMouseUp(Event* event) { EventMouse* e = (EventMouse*)event; log("mouse up. key = %d (%g, %g)", e->getMouseButton(), e->getCursorX(), e->getCursorY()); } void HelloWorld::onMouseMove(Event* event) { EventMouse* e = (EventMouse*)event; log("mouse move. (%g, %g)", e->getCursorX(), e->getCursorY()); } void HelloWorld::onMouseScroll(Event* event) { EventMouse* e = (EventMouse*)event; log("mouse scroll. (%g, %g)", e->getScrollX(), e->getScrollY()); }