Cocos2d-x에서 안드로이드 backbutton 처리

1. Layer 클래스의 headerfile에 함수 선언


void onKeyReleased( cocos2d::EventKeyboard::KeyCode keycode, cocos2d::Event *event );


2. Layer 클래스의 cpp 파일내 init()함수에 keypad enable 처리


this->setKeypadEnabled(true);


3. Layer 클래스의 cpp 파일내 onKeyReleased() body 구현하여 back 버튼 터치시 실행할 내용 작성


void MessageLayer::onKeyReleased( cocos2d::EventKeyboard::KeyCode keycode, cocos2d::Event *event )
{
if (keycode == EventKeyboard::KeyCode::KEY_BACK)
{
auto hScene = HomeLayer::createScene();
Director::getInstance()->replaceScene(hScene);
}
}


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s