How to make toggle for iOS game to control movement? - ios

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.

Related

UITouch Force on touchesBegan

3D touch seems really cool and I wanted to see how it would work in a musical context. I was reading a bit about 3D touch and it seems like the force property almost always reads as 0 when a touch begins (touchesBegan method).
How do I get a usable force when a touch begins because even if I'm pressing with maximum "force" I'm still getting that initial 0? I was thinking about just approximating a value within a time frame but that would involve me moving the touch. I just want a usable force upon the first touch.
Thanks!
Unfortunately this is impossible.
Every touch starts as a contact with no force at all, as soon as the user's finger makes contact (or even near-contact) with the screen. The force only starts to build as the user's finger is compressed against the screen.
The only way for touchesBegan: to report any force at all would be for it to delay artificially for a certain number of milliseconds before reporting a touch, to allow the force to build up. This would destroy the interactivity of all iOS applications; and Apple put a huge amount of work into delivering a touch the instant it is detected.

Is there a way to test if accessibility zoom is on?

I'd like to know if there is a line of code like isAccessibilityZoomOn to test if accessibility zoom is on. In a game I am working on, if you use zoom, the game glitches and a timer continuously goes, even though it shouldn't unless a finger is on the screen. I'm currently using the ccTouchesBegan method to start the timer, but if you have zoom on and use three fingers to tap the screen you can remove your fingers and the timer continues.
I don't believe Apple lets you access that kind of information. That is a strange effect, possibly caused by the tap to zoom in?

XNA - Surface - Tracking Touch Input

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

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.

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