Search code examples
androidandroid-ndkcocos2d-x

Android NDK : How to handle Back key press in Cocos2dx?


The question is all I have to say about it. I need to know how to handle the special keypresses like back, menu etc. in android NDK. I am using Cocos2dX so if you could give me a Cocos2dX specif answer that would be great.


Solution

  • In cocos2dx, each CCLayer gets the following methods that can be overriden to add functionality to them:

    class CC_DLL CCKeypadDelegate
    {
    public:
        // The back key clicked
        virtual void keyBackClicked() {}
    
        // The menu key clicked. only avialble on wophone & android
        virtual void keyMenuClicked() {};
    };
    

    CCLayer inherits from CCKeypadDelegate. And each screen can give implementation to these functions.