As I see it (but I might be wrong, as I haven’t made a thorough investigation) the key are lines 10-14:
auto listener = EventListenerKeyboard::create();
listener->onKeyPressed = CC_CALLBACK_2(KeyboardTest::onKeyPressed, this);
listener->onKeyReleased = CC_CALLBACK_2(KeyboardTest::onKeyReleased, this);
You have to make listener that will listen to the keyboard events (first line of above code). Then set methods which it will call, when the button is pressed or released using callbacks (2-3). At the end you give the
EventDispatcher pointer to your listener, so it can begin to work (
_eventDispatcher member pointer is here and already set, because it is inherited from
PLEASE SOMEONE CORRECT ME HERE:
addEventListenerWithSceneGraphPriority(EventListener* listener,Node* node) method I think is doing, is arranging all the
listener s from different
node s in the order they (the
node s) appear on the screen, so they can be called sequentially or they could swallow events preventing them from going any deeper (but I don’t know how, it’s only a guess).
I myself am eager to find the ‘proper’ way of handling keyboard, so give me an feedback if it works for you and maybe we’ll find it
One last thing I would recommend is not getting used to any type of API that is provided in develop branch, because it will most likely be changed a dozen of times.