Skip to content

Instantly share code, notes, and snippets.

@sdabet
Last active December 18, 2015 03:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdabet/5719684 to your computer and use it in GitHub Desktop.
Save sdabet/5719684 to your computer and use it in GitHub Desktop.
Handle Android back button in cocos2d-iphone with Apportable (in MyNavigationController class)
#ifdef APPORTABLE
- (BOOL) canBecomeFirstResponder
{
return YES;
}
- (void)buttonUpWithEvent:(UIEvent *)event
{
switch (event.buttonCode)
{
case UIEventButtonCodeBack:
// Back button is pressed
// Pop current scene
[[CCDirector sharedDirector] popScene];
// Terminate the app if scene stack is empty
if([[CCDirector sharedDirector] runningScene] == nil) {
exit(0);
}
break;
case UIEventButtonCodeMenu:
// show menu if possible.
break;
default:
break;
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment