Is there a way to detect touch events from another class than the Layer itself. I'm trying to have a state controlling the interaction, adding listener to the layer itself if needed instead of have the layer call a function on the current state, which might be a noop. Is the a way to use such a thing?
+1
A:
See the class CCTouchDispatcher
(http://www.cocos2d-iphone.org/api-ref/latest-stable/interface_c_c_touch_dispatcher.html)
You can subscribe any class that implements CCStandardTouchDelegate
or CCTargetedTouchDelegate
to receive touch events, by calling:
[[CCTouchDispatcher sharedDispatcher] addStandardDelegate:self priority:1];
on your onEnter
method (assuming your class is a CCNode
), and then remove it from the dispatcher via:
[[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
at your onExit
method.
pgb
2010-06-30 22:56:10
Is subclassing CCNode a necessity for this to work?
sharvey
2010-07-09 22:10:17