Hardware Back Button Support in Cocos2D-X Android

I’ll admit I overlooked (plain didn’t bother) adding back button support to my game Arrow Mania on Android, it will be there in the next update though! Turns out it is really easy to implement too, just a few steps:

In your CCLayer class (your main game class) add the following line to the header file:

[codebox 1]

Then in the .cpp file simply add the function like below:

[codebox 2]

And that’s it! Works in cocos2d-2.0-x-2.0.2 and beyond.