Cocos2d-3.x_Android物理按键回调

Cocos2d-3.x_Android物理按键回调,第1张

概述#ifndef __HELLOWORLD_SCENE_H__#define __HELLOWORLD_SCENE_H__#include "cocos2d.h"USING_NS_CC;class HelloWorld : public cocos2d::Layer{public: static cocos2d::Scene* createScene(); vi
#ifndef __HELLOWORLD_SCENE_H__#define __HELLOWORLD_SCENE_H__#include "cocos2d.h"USING_NS_CC;class HelloWorld : public cocos2d::Layer{public:    static cocos2d::Scene* createScene();    virtual bool init();    CREATE_FUNC(HelloWorld);private:	LabelTTF *pLabel;};#endif // __HELLOWORLD_SCENE_H__
#include "HelloWorldScene.h"Scene* HelloWorld::createScene(){    auto scene = Scene::create();    auto layer = HelloWorld::create();    scene->addChild(layer);    return scene;}bool HelloWorld::init(){    if ( !Layer::init() )    {        return false;    }        Size visibleSize = Director::getInstance()->getVisibleSize();    Vec2 origin = Director::getInstance()->getVisibleOrigin();	pLabel = LabelTTF::create("HelloWorld","Fonts/Arial.ttf",30);	pLabel->setposition(visibleSize.wIDth / 2.0,visibleSize.height / 2.0);	this->addChild(pLabel);	// 回调AndroID的物理按键事件	auto Listener = EventListenerKeyboard::create();	Listener->onKeypressed = [](EventKeyboard::KeyCode keyCode,Event *e)	{		log("keyCode:%d",keyCode);		switch (keyCode)		{		case EventKeyboard::KeyCode::KEY_BACKSPACE:		{			log("back is pressed");			Director::getInstance()->end();		}			break;		case EventKeyboard::KeyCode::KEY_MENU:		{			log("menu is pressed");		}			break;		}	};	Director::getInstance()->getEventdispatcher()->addEventListenerWithSceneGraPHPriority(Listener,this);    return true;}
总结

以上是内存溢出为你收集整理的Cocos2d-3.x_Android物理按键回调全部内容,希望文章能够帮你解决Cocos2d-3.x_Android物理按键回调所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1054182.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-25
下一篇2022-05-25

发表评论

登录后才能评论

评论列表(0条)

    保存