【问题标题】:Cocos2d iphone touch eventCocos2d iphone 触摸事件
【发布时间】:2010-06-30 22:32:58
【问题描述】:

有没有办法检测除图层本身之外的另一个类的触摸事件。 我试图让一个状态控制交互,如果需要,将侦听器添加到层本身,而不是让层调用当前状态的函数,这可能是一个 noop。 有没有办法使用这种东西?

【问题讨论】:

    标签: iphone objective-c cocos2d-iphone touch


    【解决方案1】:

    查看课程CCTouchDispatcher (http://www.cocos2d-iphone.org/api-ref/latest-stable/interface_c_c_touch_dispatcher.html)

    您可以订阅任何实现CCStandardTouchDelegateCCTargetedTouchDelegate 的类以接收触摸事件,方法是调用:

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

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

    [[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
    

    在您的onExit 方法中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多