Hi,
Could anyone explain, in a nutshell, the use of the SwallowsTouches and Priority settings?
- (void)onEnter
{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
[super onEnter];
}
Regards
i
A fast, easy to use, free, and community supported 2D game engine
Hi,
Could anyone explain, in a nutshell, the use of the SwallowsTouches and Priority settings?
- (void)onEnter
{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
[super onEnter];
}
Regards
i
bump ;-)
@indy2005,
CCTouchDispatcher Class Reference
Priority: lower number = higher priority. That's why in some examples, you'll see the priority set to INT_MIN + 1 or something similar, so you can be sure you are giving the highest priority to that touch handler
Swallows touches: If you set it to YES, the touch get's 'swallowed', and not propogated to another object.
-Mark
Thanks, so does priority indicate which touch dispatchers get passed the touch first? i.e. which get first opportunity to "swallow".
ANd what does swallow mean, does it mean if you return "yes" in TouchesBegan and "claim the touch" no other delegate receives it? or is "Swallow" a different concept to this claiming of a touch (no dirty swallow jokes please)?
Regards
i
Exactly,
lower number (higher priority) gets to see the touch first, swallow decides if the touch gets passed along to the next touch handler or not.
-Mark
Hi,
Thanks, sorry to labour the point (I'm a bit thick!!). If I have two delegates, each with the same priority, and both swallows touches....how does that work? How is this related to "claiming a touch" in TouchesBegan. How does this get affected by multi-touch?!
Regards
i
indy2005,
Not positive about the same priority.. if that's the case, I would assume it goes by who registered the touch handler first, but you could always take a look at the implementation, or just mock something up and mess with it to see what the results are. That's the best way to figure out what is going on. You could take the TouchesTest from the 0.94 project, and play around with it to see what the results are.. put some more CCLOG's in there if you are confused about the order of events. Maybe add more paddles, on top of the other paddles, change the touch handler priority and swallowsTouches values, and see what happens.
Hi,
Its one of those elusive things for me. Everyone always refers to Paddles as the ultimate learning tool for the touch dispatcher, but in terms of priorities, swallows and claims....its all a bit of a black art in terms of how they all interact.
I guess it doesnt help comin straight into Cocos2d without first learning basic iPhone dev!
Thanks
i
indy2005,
I'd recommend, if you are a little unsure about how things are executing, to just pepper that touchesTest project with CCLOG statements where you'd like to see what's going on.. Then watch the debugging console to see when and where those log statements are run.
There's always a better way, but, sometimes when I want to drill in and make sure I understand the order of execution, I use this macro:
//#define LOGTHIS {};
#define LOGTHIS {(CCLOG(@"\t\t[%@ - %@]", self, NSStringFromSelector(_cmd)));}
and just put:
LOGTHIS;
wherever I want to verify what's being executed when. It just prints the method name wherever it's put. It's been helpful to me every now and then.
There's another one I had that would send console messages whenever there was a notification event, like onOrientationChanged, or appDidFinishLaunching, or the like.. can't find that one right now.
Anyway, like I said, just log it.. it will help you understand the flow of the program.
HTH,
-Mark
Thanks...will post back for my own understanding
You must log in to post.