Cocos2dx3.1.1 android返回键控制


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

auto listener1 = EventListenerKeyboard::create();
    listener1->onKeyReleased = CC_CALLBACK_2(PlayScene::onKeyReleased, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener1, this);



void PlayScene::onKeyReleased(EventKeyboard::KeyCode keycode, Event* event)
{

	if ((int )keycode == 6 || keycode == EventKeyboard::KeyCode::KEY_BACKSPACE){
		//返回
		this->stopAction();
		auto scene = MainScene::scene();
		//加载PlayScene  
		Director::getInstance()->replaceScene(scene);
	}
    else if (keycode == EventKeyboard::KeyCode::KEY_MENU)
    {
      //  _label->setString("MENU clicked!");
    }
}



你可能感兴趣的:(Cocos2dx3.1.1 android返回键控制)