zoukankan      html  css  js  c++  java
  • Cocos2d-x3.0 捕捉Android的菜单键和返回键

    .cpp文件
    auto listener = EventListenerKeyboard::create();
    
    	listener->onKeyReleased = CC_CALLBACK_2(HelloWorld::onKeyReleased, this);
    
    	Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this);

    void  HelloWorld::onKeyReleased(EventKeyboard::KeyCode keycode, cocos2d::Event *event){
    
    	switch (keycode){
    
    	case cocos2d::EventKeyboard::KeyCode::KEY_BACKSPACE:
    
    	case cocos2d::EventKeyboard::KeyCode::KEY_BACK:
    
    #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
    
    		MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.", "Alert");
    
    		return;
    
    #endif
    
    		Director::getInstance()->end();
    
    #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    
    		exit(0);
    
    #endif
    
    		break;
    
    	default:
    
    		break;
    
    	}
    }

    .h文件
     virtual void onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event);

    在此前是不够的,一定注意在.h文件中添加USING_NS_CC;否则会报错。
  • 相关阅读:
    hashlib模块
    configparser模块
    xml模块和shelve模块
    json与pickle模块
    3/30
    os模块
    sys模块
    shutil模块
    random模块
    2月书单《编码隐匿在计算机软硬件背后的语言》 13-16章
  • 原文地址:https://www.cnblogs.com/Anzhongliu/p/6091812.html
Copyright © 2011-2022 走看看