I’ve been using Cocos2d-X 2.1.4 for a few months now and feel somewhat confident with it. I downloaded the 3.0 Alpha build a couple of days ago after deciding to build a desktop game (OSX/Windows). Keyboard/touch input was easy with 2.1.4, but it appears to be a bit more difficult on 3.0.
Does anyone know how keyboard/mouse input works for Windows/Mac?
I’ve spent 2 days looking around at the samples, tutorials, other forum posts and so on, and have not found an answer. It is getting frustrating as this was a lot easier with the previous Cocos2d-X.
Tried to recompile project made about month ago with today (30 X 2013) develop branch and it won’t go. First problem was that Layer::setKeyboardEnabled() method is no longer here. When I commented those lines it compiled, but nothing hapened when buttons were pressed.
Then I checked keyboard test from project:
And here I found how does it work now. Hope it helps.
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 Node).
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.