cocos2dx自学之 事件监听

cocos2dx自学之 事件监听,第1张

概述auto label = LabelTTF::create("click me!","Courier",30); label->setPosition(visibleSize.width/2,visibleSize.height/2); addChild(label); auto listener = EventListenerTouchOneByOne::create(); //创建监听
auto label = LabelTTF::create("click me!","CourIEr",30);	label->setposition(visibleSize.wIDth/2,visibleSize.height/2);	addChild(label);	auto Listener = EventListenertouchOneByOne::create(); //创建监听器	Listener->ontouchBegan = [](touch *touch,Event *event){  //设置监听函数				if(event->getCurrentTarget()->getBoundingBox().containsPoint(touch->getLocation())){ //判断点击范围是在label上			log("ontouched!!!!!!!!!!!!");		}		return true;  //返回true才能出发事件传递	};	//事件传递	Listener->ontouchmoved = [](touch* touch,Event *event){ //拖动事件   ontouchended = 触摸d起事件		log("ontouchmoved!");		return true;//返回 true  才可以继续传递事件	};	Director::getInstance()->getEventdispatcher()->addEventListenerWithSceneGraPHPriority(Listener,label);  //绑定监听事件 */	//多点触摸监听器******************************************	/*auto Listener = EventListenertouchAllAtOnce::create();		Listener->ontouchesBegan = [](std::vector<touch*> t,Event *event){ //单击事件		log("ontouchesBegan");	};	Listener->ontouchesMoved = [](std::vector<touch*> t,Event *event){ //多点同时触摸事件		log("touches moved,and touch count is%ld",t.size());	};	Director::getInstance()->getEventdispatcher()->addEventListenerWithSceneGraPHPriority(Listener,this); */	/****************************  传感器  *****************************************/	/*Device::setAccelerometerEnabled(true);//打开传感器侦听  传感器=重力感应?	auto Listener = EventListeneracceleration::create([](acceleration *a,Event *event){		log("x:%g,y:%g,z:%g",a->x,a->y,a->z);	});	Director::getInstance()->getEventdispatcher()->addEventListenerWithSceneGraPHPriority(Listener,this);*/	/**************************  按键监听  ************************************/	/*auto Listener = EventListenerKeyboard::create();	Listener->onkeyreleased = [](EventKeyboard::KeyCode code,Event *venet){ //监听按键事件		log("key:%d",code);		switch(code){  		case EventKeyboard::KeyCode::KEY_BACKSPACE: //如果是后退键			Director::getInstance()->end();   //退出当前程序				break;		}	};	Director::getInstance()->getEventdispatcher()->addEventListenerWithSceneGraPHPriority(Listener,this);
总结

以上是内存溢出为你收集整理的cocos2dx自学事件监听全部内容,希望文章能够帮你解决cocos2dx自学之 事件监听所遇到的程序开发问题。

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

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

原文地址: http://outofmemory.cn/web/1066054.html

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

发表评论

登录后才能评论

评论列表(0条)

保存