cocos2dx 接受触摸事件

前端之家收集整理的这篇文章主要介绍了cocos2dx 接受触摸事件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

有两种方式

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)
原文链接:https://www.f2er.com/cocos2dx/338945.html

猜你在找的Cocos2d-x相关文章