• 12
• 12
• 9
• 10
• 13

iPhone multiTouch : how do i know which phaseBegin the current phaseMoved belongs to?

This topic is 3261 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

hello, To clarify what i want to say, here is an example : i use two thumbs to control player's yaw and pitch, both thumbs are touched down on the screen, later at the moment i received a 'moved' event, how do i know the received event is used for controlling the yaw or pitch of the player? in this case, if there is a way to know which touchBegin the current 'moved' event belongs to would be very helpful, what do you think? thanks a lot.

Share on other sites
There isn't any data within the event to give you a definitive answer about which touch the movement event belongs too, I looked. You'll have to do the tracking yourself. I keep an array of active touches and compare distances, the closest one last frame becomes the touch move owner for that touch instance.

Good Luck!

-ddn

Share on other sites
UITouches persist through a phase. They get destroyed after touchesEnded: has been called. so you can distinguis them just by their adress in memory.

just keep two weak references to them and check for them when movements occur ...

for example:

UITouch *_leftTouch; UITouch *_rightTouch;- (BOOL) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{  //let's assume that the first touch is the left one  //and the second the right ...   //you'll have to distinguish them by checking their location  //we assume also that there are 2 touches - (check [touches count]!)  _leftTouch = [touches objectAtIndex: 0];  _rightTouch = [touches objectAtIndex: 1];  return kEventHandled;}...- (BOOL)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{   //again check [touches count] to see how many fingers moved   //but here we just assume that one finger moved  if ([touches objectAtIndex: 0] == _leftTouch)  {   //do left stuff  }  return kEventHandled;}

this should be it. it's a while since i was doing input handling - so maybe touches is not the right set (check [event allTouches] if touches should not work)

Share on other sites
I must say that's some crazy programming paradigm Obj-C uses, where you can store ptrs to events :D I've always programmed with the idea that event are transient objects you never hold on to. Is Obj-C garbage collected like C#?

-ddn

Share on other sites
Quote:
 I must say that's some crazy programming paradigm Obj-C uses, where you can store ptrs to events :D

you don't really hold on the events. you hold the touches. and creating persistent "touch objects" as long as the physical touch persists is pretty logical to me.

Quote:
 Is Obj-C garbage collected like C#?

not on the iphone.
for desktop macs you can enable the GC on mac os x 10.5+.

manual obj-c memory managment (refcounting) can be sometimes confusing for people and if you don't grasp it it can be a serious source of bugs. so i would recommend to read apples docs on the memory-managment techniques used in obj-c/cocoa. (or to write your iphone games in c++ and just provide some glue-code to the interface in obj-c)