
有两种方式
1.重写 多点触摸
virtual voID ontouchesBegan (const std::vector< cocos2d::touch * > &touches,cocos2d::Event *unused_event);
2. 注册 单点触摸
auto dispatcher = Director::getInstance()->getEventdispatcher(); auto Listener = EventListenertouchOneByOne::create(); Listener->ontouchBegan = CC_CALLBACK_2(HelloWorld::ontouchBegan,this); Listener->ontouchmoved = CC_CALLBACK_2(HelloWorld::ontouchmoved,this); Listener->ontouchended = CC_CALLBACK_2(HelloWorld::ontouchended,this); Listener->setSwallowtouches(true);//不向下传递触摸 dispatcher->addEventListenerWithSceneGraPHPriority(Listener,this);
然后 重写
bool HelloWorld::ontouchBegan(touch* touch,Event *event) voID HelloWorld::ontouchended(cocos2d::touch *touch,cocos2d::Event *unused_event)总结
以上是内存溢出为你收集整理的cocos2dx 接受触摸事件全部内容,希望文章能够帮你解决cocos2dx 接受触摸事件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)