cocos2d:ccTouchesBegan 未调用,但 ccTouchBegan 确实触发
我试图让我的 CCLayer 子类响应多点触控。在 init 方法中,我调用
self.isTouchEnabled=YES;
在名为 registerWithTouchDispatcher 的方法中,我调用
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:NO];
在我的应用程序委托中,我调用
[glView setMultipleTouchEnabled:YES];
ccTouchBegan:withEvent: 方法被调用,但从未调用 ccTouchesBegan:withEvent。我对 cocos2d 很陌生,所以它可能很简单,我只是不明白它是什么。
I am trying to have my subclass of CCLayer respond to multitouch. In the init method I call
self.isTouchEnabled=YES;
In a method called registerWithTouchDispatcher, I call
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:NO];
In my app delegate, I call
[glView setMultipleTouchEnabled:YES];
The ccTouchBegan:withEvent: method gets called, but never the ccTouchesBegan:withEvent. I am pretty new to cocos2d, so it could be something simple, I just can't figure out what it is.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的类中添加
[[CCTouchDispatcher sharedDispatcher] addStandardDelegate:selfpriority:0];
以接收非目标触摸。来自cocos2d文档(链接:http://www.cocos2d-iphone.org/api -ref/0.99.0/interface_c_c_touch_dispatcher.html)
CCTouchDispatcher。处理所有触摸事件的单例。调度程序将事件调度到已注册的 TouchHandler。有 2 种不同类型的触摸处理程序:
标准触摸处理程序
目标触摸处理程序
标准触摸处理程序的工作方式类似于 CocoaTouch 触摸处理程序:一组触摸被传递给委托。另一方面,目标触摸处理程序一次仅接收 1 次触摸,并且它们可以“吞噬”触摸(避免事件的传播)。
首先,调度程序将接收到的触摸发送到目标触摸。这些触摸可以被目标触摸处理程序吞噬。如果仍有剩余触摸,则剩余触摸将被发送到标准触摸处理程序。
Add
[[CCTouchDispatcher sharedDispatcher] addStandardDelegate:self priority:0];
in your class to receive non targeted touches.From the cocos2d documentation (Link: http://www.cocos2d-iphone.org/api-ref/0.99.0/interface_c_c_touch_dispatcher.html)
CCTouchDispatcher. Singleton that handles all the touch events. The dispatcher dispatches events to the registered TouchHandlers. There are 2 different type of touch handlers:
Standard Touch Handlers
Targeted Touch Handlers
The Standard Touch Handlers work like the CocoaTouch touch handler: a set of touches is passed to the delegate. On the other hand, the Targeted Touch Handlers only receive 1 touch at the time, and they can "swallow" touches (avoid the propagation of the event).
Firstly, the dispatcher sends the received touches to the targeted touches. These touches can be swallowed by the Targeted Touch Handlers. If there are still remaining touches, then the remaining touches will be sent to the Standard Touch Handlers.