Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 667
prometheuspk Avatar asked May 28 '12 08:05

prometheuspk


2 Answers

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.

like image 167
Muhammed Alee Avatar answered Oct 04 '22 00:10

Muhammed Alee


In Cocos2d-x You have to do that implement

 virtual void keyBackClicked();

and also this

 this->setKeyPadEnable(true);

in .cpp class

like image 22
Singhak Avatar answered Oct 04 '22 00:10

Singhak