Layer should not be an event controller class anymore, and any classes should have the ability of receiving events.
EventDispatcher has unified all event dispatching.
Before, we have
Now, we just need one
If you like the old controller codes. You could very easily to achieve that.
For example, adding a new method called
void YourClass::setTouchEnabled(bool enabled)
_touchListener = EventListenerTouchOneByOne::create();
_touchListener->onTouchBegan = CC_CALLBACK_2(YourClass::onTouchBegan, this);
_touchListener->onTouchMoved = CC_CALLBACK_2(YourClass::onTouchMoved, this);
_touchListener->onTouchEnded = CC_CALLBACK_2(YourClass::onTouchEnded, this);
_touchListener->onTouchCancelled = CC_CALLBACK_2(YourClass::onTouchCancelled, this);
Another thing is if a listener is added by
addEventListenerWithSceneGraphPriority, the event will be dispatched by the
draw order of scene graph.
That means the node at the top of screen will receive event first.
In the 2.x version, you have to set the priorities by yourself. It's very very hard to manage the order of dispatching.
So I don't know why you hate the new EventDispatcher, anyway
EventDispatcher is designed by me and all guys who have joined the design.
The principle is
Nodes should not contain
event controller codes.
Any classes should have the ability to access events.
* All events should be dispatched by the same strategy, that's why we need the new
If you guys don't like it, please be more specified about the reason.
If you guys have better approaches, feel free to let me know. I'm glad to correct all my mistakes if there're.