Cocos2d-x Lua Keyboard Events: Press, Release and Listener Cleanup
Register Keyboard Press and Release Callbacks
Cocos2d-x 3.17 exposes keyboard events to Lua through cc.EventListenerKeyboard. A listener needs callbacks for key presses and releases, and it must be attached to a node through the event dispatcher.
| |
Call it after the node has been created:
Scene-graph priority associates the listener with the node, so it follows the node’s running state and is normally removed with it. If a listener was registered with fixed priority or needs early cleanup, remove it explicitly:
Keep platform differences in mind: desktop builds provide physical keyboard events, while mobile gameplay normally needs touch controls or a text-input component. Key-code names can also vary with the Cocos2d-x binding version, so check the constants generated for the project when a particular key is not recognized.