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
开发者_如何学Python[[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.
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.
精彩评论