Sign in to follow this  
Pet123

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

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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)

Share this post


Link to post
Share on other sites
thanks for all the replys.

you are right, jrk, the touch object (created when touchBegin and died when touchEnd) is always there, so its possible to use the touch object's address (as ID) to dispatch events.

thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this