yagoub
September 14, 2014, 7:52am
#1
Hi,
i have implemented the back button android using coco2d-x V3.0, like this:
HelloWorld.h
void onKeyReleased( cocos2d::EventKeyboard::KeyCode keycode, cocos2d::Event *event );
HelloWorld.cpp
this->setKeypadEnabled( true );
void HelloWorld::onKeyReleased( cocos2d::EventKeyboard::KeyCode keycode, cocos2d::Event *event )
{
Director::getInstance()->end();
}
but now if i touch the back button and i lock the screen, the application didn’t exit complitly, and will crash when i unlock the screen !
Could you please help me to deal with this problem ?
hzlov
September 14, 2014, 11:53am
#2
void HelloWorld::onKeyReleased( cocos2d::EventKeyboard::KeyCode keycode, cocos2d::Event *event )
{
if (keyCode == EventKeyboard::KeyCode::KEY_ESCAPE){
Director::getInstance()->end();
}
}
You don’t need keypad for it.
I’m sorry I can say nothing for crash thing.
hzlov
September 14, 2014, 4:50pm
#4
There are many possibilities for crash.
Look carefully when app crashes from adb logcat.
yagoub
September 14, 2014, 5:15pm
#5
When i made this condition
if (keyCode == EventKeyboard::KeyCode::KEY_ESCAPE){
Director::getInstance()->end();
}
i have no reaction !
hzlov
September 14, 2014, 5:57pm
#6
Then you can create EventListner for keyboard at onEnter or init().
_listenerKeyboard = EventListenerKeyboard::create();
_listenerKeyboard->onKeyReleased = CC_CALLBACK_2(HellowWorld::onKeyReleased, this);
getEventDispatcher()->addEventListenerWithSceneGraphPriority(_listenerKeyboard, this);
You should see what’s the difference between Node and Layer.
yagoub
September 15, 2014, 8:44am
#7
Thanks, but does it work only for the physic button or also the back touch on the screen