代码之家  ›  专栏  ›  技术社区  ›  sharvey

Cocos2d iphone touch事件

  •  1
  • sharvey  · 技术社区  · 16 年前

    有没有一种方法可以从层本身以外的另一个类中检测触摸事件。 这是使用这种东西的一种方法吗?

    1 回复  |  直到 16 年前
        1
  •  2
  •   pgb    16 年前

    看到班级了吗 CCTouchDispatcher ( http://www.cocos2d-iphone.org/api-ref/latest-stable/interface_c_c_touch_dispatcher.html )

    您可以订阅任何实现 CCStandardTouchDelegate CCTargetedTouchDelegate

    [[CCTouchDispatcher sharedDispatcher] addStandardDelegate:self priority:1];
    

    在你的 onEnter 方法(假设您的类是 CCNode ),然后通过以下方式将其从dispatcher中删除:

    [[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
    

    onExit 方法。