tags:

views:

391

answers:

2

I started using the MoveMe sample to get touch input working.

basically, I define these two callback functions to get my touch input:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{

    for ( UITouch* touch in touches )
    {
        printf("touch down");
    }
}



- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{
    for ( UITouch* touch in touches )
    {
        printf("touch up");
    }
}

This works fine, until you have more than 5 touches on the screen at once. then it stops working properly, you won't get the "touch down" message if there are more than 5 touches on the screen. what is even worse is that you won't reliably get all of the "touch up" messages until you have removed ALL your fingers from the screen.

If you touch with 6 fingers, then release 3, then touch again with the other 3 still down, you will get the "touch down" but if you release it, some times you get the "touch up" sometimes you don't.

This pretty much makes it impossible to track touches, and usually results in a touch getting 'stuck' permanently down, when passed to my Touch Manager.

Are there some better apis to use to get touch input? is there at very least a function you can call to reliably get whether the screen is currently touched or not? that way I could reset my manager when all fingers are released.

EDIT:

right, there must be something I'm missing. because currently the calculator does something I cannot do with those callbacks.

it only accepts one touch at a time, if there is more than one touch on the screen it "cancels" all touches, but it must keep track of them to know that there is "more than one" touch on the screen.

if I touch the screen the button goes down, now if I add another touch to the screen, the button releases, cool, not allowed more than one touch. now, if I add 4 more fingers to the screen, for a total of 6, the screen should break, and when I release those 6 fingers, the app shouldn't get any of the "up" callbacks. yet when I release all of them and touch again, the button depresses, so it knows I released all those fingers!! how??

+1  A: 

It stops working because 5 is the max amount of touches that the iPhone and iPod currently support. No way around that I'm afraid.

St3fan
hmm, so how do people get around buttons being stuck down and stuff because they have left over touches stuck on the screen? the way my manager works is, it adds a touch to the manager when it gets the "begin" event for it, and then deletes it when it gets its end event.as I'm not getting some end events, this leaves touches stuck on the screen!?
matt
Is this documented somewhere?
Tim
I mean this is just pathetic! there must be at least some absolute way to tell if the screen is being touched at all!? that way at least I could clear my touch manager!
matt
Uh. Not many apps require 6 fingers on the screen?
St3fan
+1  A: 

The problem you have is that the iPhone and iPod touch only support up to five touches at the same time (being fingers still touching the screen). This is probably a hardware limit.
(As St3fan told you already.)

The system will cancel all touches if there are more than 5 at the same time: touchesCancelled:withEvent: (This is probably what causes the odd behavior with only some touches calling touchesEnded:withEvent:)

If you want to know if a touch ended and it ended because it was lifted then make sure to check the UITouch's phase property.

bddckr
Thanks! that's perfect. just to clarify, my problem was never that I WANTED to process more than 5 touches. it was if the user happened to touch the screen more than 5 times (something I have no control over...) it would break my system without that touchesCancelled event.I was just thinking myself that my own touch manager would need to let the user know the difference between a touch up and a cancel, so this makes sense. This is what happens when you use sample code as a base...
matt