Cocos2xd__ user events

Event Class Event: class Event: public Ref

Its subclasses:

  1. EventTouch: Touch event

  2. EventMouse: Mouse Events

  3. EventKeyboard: keyboard events

  4. EventAcceleration: acceleration event

  5. EventCustom: Custom Events

 

Event Source:

  Elf layers, menus, etc. node object.

 

Event handler: EventListener

  class EventListener : public Ref

  Its subclasses:

  1. EventListenerTouchOneByOne: single-point touch event listeners

  1. EventListenerTouchAllAtOnce: multi-touch event listeners

  2. EventListenerMouse: Mouse Event Listener

  3. EventListenerKeyboard: keyboard event listener

  4. EventListenerAcceleration: acceleration event listener

  5. EventListenerCustom: custom event listeners

 

Listeners can look at the event and the event has a corresponding relationship. That can only be handled by keyboard keyboard event listener.

 

EventDispatcher event dispatcher is responsible for registering and deregistering listeners and event distribution. Design uses a single embodiment.

You can use _eventDispatcher event registration and logout events, such as:

   _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, node); 

 

EventDispatcher look at event management method provides:

First, the registration events:

  1. void addEventListenerWithSceneGraphPriority(EventListener* listener, Node* node)

  2. void addEventListenerWithFixedPriority(EventListener* listener, int fixedPriority)

  3. EventListenerCustom* addCustomEventListener(const std::string &eventName, const std::function<void(EventCustom*)>& callback)

Second, the cancellation of the event:

  1. void removeEventListener(EventListener* listener)

  2. void removeAllEventListeners()

  3. void removeCustomEventListeners(const std::string& customEventName)

  4. void removeEventListenersForTarget(Node* target, bool recursive /* = false */)

  5. void removeEventListenersForType(EventListener::Type listenerType)

 

1. Touch the event:

Touch events can be divided into three stages: Press, move, lift

There are two touch event listeners: EventListenerTouchOneByOne, EventListenerTouchAllAtOnce

EventListenerTouchOneByOne in response to a touch event attributes:

  1. std :: function <bool (Touch *, Event *)> onTouchBegan: callback when the touch screen, you can continue to return true if the callback 2, 3, or not callback.

  2. std :: function <void (Touch *, Event *)> onTouchMoved: callback when moving the screen

  3. std :: function <void (Touch *, Event *)> onTouchEnded: leave the screen callback

  4. std :: function <void (Touch *, Event *)> onTouchCancelled: single-point touch event is canceled callback

  NOTE: std :: function package is a generic function, see C ++.

EventListenerTouchAllAtOnce  in response to a touch event attributes:

  1. std :: function <void (const std :: vector <Touch *> &, Event *)> onTouchBegan: multi-touch callback, you can continue to return true if the callback 2, 3, or not callback.

  2. std :: function <void (const std :: vector <Touch *> &, Event *)> onTouchMoved: multi-point pullback in the mobile screen

  3. std :: function <void (const std :: vector <Touch *> &, Event *)> onTouchEnded: multi-point off the screen callback

  4. std :: function <void (const std :: vector <Touch *> &, Event *)> onTouchCancelled: multi-touch event is canceled callback

//

 

Guess you like

Origin www.cnblogs.com/teternity/p/Cocos2xd__Event.html