【问题标题】:Which EventDispatcher to use in cocos2d ? Node::EventDispatcher or Director::EventDispatcher?在 cocos2d 中使用哪个 EventDispatcher ? Node::EventDispatcher 还是 Director::EventDispatcher?
【发布时间】:2020-04-28 18:13:47
【问题描述】:

在 cocos2d 中使用哪个 EventDispatcher ? Node::EventDispatcher 还是 Director::EventDispatcher ? 参考了Director类和Node类的官方文档后 Director Class Reference Cocos2d-x Node Class Reference Cocos2d-x 我有点困惑,使用

有什么区别
Director::getInstance()->getEventDispatcher() // consider this is used inside a class which is derived from Node class

this->getEventDispatcher() // consider this refers to a class derived from Node class

【问题讨论】:

    标签: cocos2d-x cocos2d-x-3.0 symfony-eventdispatcher


    【解决方案1】:

    两者都是一样的。 this->getEventDispatcher() 调用 CCNode 的 getEventDispatcher() 函数。它返回 _eventDispatcher。

    _eventDispatcher = _director->getEventDispatcher(); // Check CCNode.cpp
    

    所以这三个是一样的

    Director::getInstance()->getEventDispatcher()->addEventListenerWith..
    
    this->getEventDispatcher()->addEventListenerWith..
    
    _eventDispatcher->addEventListenerWith..
    

    注意:我刚刚检查了 Cocos2d-x 4.0

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-17
      • 1970-01-01
      相关资源
      最近更新 更多