Director :: getInstance() - > getTouchDispatcher()在cocos2d中没有cocos2d :: Director中名为getTouchDispatcher()的成员给出错误

时间:2015-12-28 09:13:59

标签: ios c++11 xcode6 cocos2d-x

请给我一些替代解决方案 onEnter()方法

{
   Director::getInstance()->getTouchDispatcher()->addTargetedDelegate(this, 0, false);

    Layer::onEnter();
}

1 个答案:

答案 0 :(得分:0)

在cocos2d 3.9中,您可以使用如下所述的块来检测触摸。您可以在onEnter中编写以下代码。有关更多详细信息,请查看cocos2d-x编程指南:http://www.cocos2d-x.org/programmersguide/8/index.html

//  Create a "one by one" touch event listener
// (processes one touch at a time)
auto listener1 = EventListenerTouchOneByOne::create();

// trigger when you push down
listener1->onTouchBegan = [](Touch* touch, Event* event){
    // your code
    return true; // if you are consuming it
};

// trigger when moving touch
listener1->onTouchMoved = [](Touch* touch, Event* event){
    // your code
};

// trigger when you let up
listener1->onTouchEnded = [=](Touch* touch, Event* event){
    // your code
};

// Add listener
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener1, this);