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;否则会报错。
  • 相关阅读:
    js事件循环机制event-loop
    javascript编译与执行
    css中rem,em,px的区别和使用场景
    float
    flex布局
    azoux's blog
    1004 成绩排名 PAT Basic Level
    1003 我要通过! PTA Basic Level
    腾讯云防盗链测试
    简单多项式求解
  • 原文地址:https://www.cnblogs.com/Anzhongliu/p/6091812.html
Copyright © 2011-2022 走看看