XNA - Surface - Tracking Touch Input - xna

How do I track a person's finger moving on the surface when using XNA?
I have managed to get all the touch points and record them but I don't know how to check if a person moved their finger or released the press and pressed again somewhere nearby.
I searched for TouchPoint.Id which looked promising but I don't know how it works and documentation is lacking.
I need this in order to handle proper button input (wherein if a person moves their finger out of the button bounds after pressing down on it then that doesn't count as a press).

The ID will be the same for a given finger until that finger is lifted up. IDs get recycled so you need to look at every input frame to know when a finger was lifted.
There is an "interaction framework" sample in the Surface SDK that implements concepts like input capture and skinnable button/list controls with XNA

Related

iOS Magic Keyboard APIs

Is it possible to intercept the trackpad events from the magic keyboard (with trackpad) in an iOS app and process them myself while hiding the pointer and not sending these events to the UI, or is that not possible?
Think about a game for instance where the user would move their finger around on the trackpad to move a character around on screen, but you wouldn't want to show the pointer circle and the location on the screen doesn't matter or if/where they click, you are just using the change in position as they move their finger on the trackpad.
Thanks

Is there any way to keep touches alive in iOS?

I'm testing the touch detection capabilities of the iPad (specifically iPad 3 at the moment). I'm printing out a log of detected touches to see what is going on, and using a bottle with three foam (touch friendly) pads at the bottom.
The touches are detected fine and it logs any slight movements which is great. The issue is that after a while if the bottle isn't moved at all, all three touches are forcibly cancelled and remain undetected until the bottle is removed and placed back down.
So it seems there's a timeout on these touches... I have not found any specific information on this. Is there any way to revive or keep alive touches without having to physically remove and restore your touch points?
A capacitive touch sensor is a very sensitive instrument, and a lot of filtering is done before the OS reports touches to you. This is also the reason why the iPad cannot detect touches with smaller contact areas than what comes with cheap styli - rubber domes of about 7mm diameter. The touchscreen controller detects smaller touches alright, but filters them to avoid spurious signals. Note that the touchscreen of a Samsung Galaxy will already detect touches with a dull pencil - the screen is (for practical purposes) the same as that of an iPad, but the cutoff for the controller is lower.
I would expect that the self-calibrating logic inside the touch controller will calibrate your touches away. Basically, it will set the signal produced by your foam pads as the new normal. On the application side there is nothing that you can do to reverse this.
Disclaimer: I have no inside knowledge of what goes on inside the touchscreen controller. My answer is based on much reading and solid reasoning, nothing more.

iOS: Detect if touchEnded comes from sliding off screen or lifting finger?

In iOS is there any way to tell, when the touch ends, if it ended by sliding off the screen or if the user lifted his finger?
I don't know why, but I expected the touch to be cancelled when this happened, but it is not.
Thanks.
This is standard iOS behavior, you may see it in any Apple's app.
You may check if touch ended at the end of screen and treat it as "cancel sliding", but user might be wanting to slide this far.
My advice is accept it, because, as I said before, it's standard behavior, and Apple tells us to stick to it - users expect standard behavior.
Only through deduction. If the finger was moving towards the edge of the screen and then the touch ends near that edge, you can be relatively certain that the finger indeed slid off the screen. If it wasn't moving immediately before the touch ended, the user probably just lifted their finger.

How to make toggle for iOS game to control movement?

I'm making an iOS game, and I want to be able to control the movement of my character with a toggle.
My idea is that when the user touches the screen with their thumb / finger, I will record where the touch began, and then whichever direction the users thumb is compared to where the touch began is the direction the character should move.
How could I setup a touch gesture recogniser to do this?
Cheers
Hmm, it sounds to me like you are thinking of this at too high of a level. You don't need a "gesture recognition system" to do this. You know how to tell whether and where the touch is down? You know how to tell what time it is? Each time through your main loop, check if the touch is down / still down. When it first goes down, record the location and time. If later you see that it hasn't gone up and it's positioned a certain number of pixels to the right, you know it slid over there. And by comparing the times you know how fast it slid over there.
And of course you might want to check out Cocos2d for a library that does some of this for you. But it's worth doing yourself first, just to learn it.

Can a swipe event fire before the user raises his or her finger?

I am using swipes to navigate through the pages of my jQuery mobile / PhoneGap application. Do you know if it is possible to let the page transition start after the swipe distance of (for example) 50 px? In other words: It should start before the finger stops touching the screen.
That would advance the user experience as they don't have this little waiting time between raising their finger and the actual page transition.
Thanks for you time!
It should be capable using the 'touchStart' and 'touchMove' events. Record the position of the touch when 'touchStart' fires and then check the displacement whenever 'touchMove' fires. If the displacement exceeds 50 px, call your page switching function. 'touchEnd' will be fired when the user lifts their finger, so you may need to compensate for that if any special actions occur then.
A good place to start is Padilicious's swipe library (http://padilicious.com/code/touchevents/). This can easily be modified to support a swipe-distance setup.
Let me know if you need anymore information.

Resources