0

在 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
4

1 回答 1

2

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

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

所以这3个是一样的

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

this->getEventDispatcher()->addEventListenerWith..

_eventDispatcher->addEventListenerWith..

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

于 2020-04-29T18:05:44.593 回答