【问题标题】:How to get touch location in Cocos2dx V3.8Cocos2dx V3.8中如何获取触摸位置
【发布时间】:2015-10-13 17:31:10
【问题描述】:

this->setTouchEnabled() 已弃用。

link 描述了如何在 V3 中执行此操作,但 _eventDispatcher 现在似乎已被弃用。

现在有谁知道在 cocos2dx 中处理触摸的正确方法吗?

编辑:

目前使用:

auto listener = cocos2d::EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = CC_CALLBACK_2(TouchableArea::touchOccoured, this);
this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this);

它有效,但我不知道这是否是理想的。

【问题讨论】:

  • 您要获取触摸位置还是禁用触摸输入?您的问题标题与问题本身完全不同。
  • 我想启用和使用触摸。

标签: c++ cocos2d-x cocos2d-x-3.0


【解决方案1】:

您可以停止/启动单独的事件监听器:

touchListener->setEnabled(false);

我现在检查了,它工作正常。 Cocos2d-x v.3.8.1.

编辑:
也不知道有没有更好的办法。但是在 cpp-tests, NewEventDispatcherTest.cpp, class PauseResumeTargetTest 中,你可以找到这些行:

sprite3->getListener()->setEnabled(false);
_eventDispatcher->pauseEventListenersForTarget(this, true);

...

_eventDispatcher->resumeEventListenersForTarget(this, true);
sprite3->getListener()->setEnabled(true);

所以,这将是官方的方式。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-15
    • 1970-01-01
    相关资源
    最近更新 更多