- Home /
Pinch vs. Rotate gestures: can they be made size/resolution-independent?
I'm trying to come up with a way to detect pinch in/out, and rotation gestures. If you delay the detection of a gesture, and allow some data to be collected for a few frames, I think this would be easy. But in Apple's Preview App, for example, the detection seems to be instantaneous to me.
As far as I can tell, in Preview, the only differences between a pinch and a rotate gesture lie with detecting distances between the positions of the two fingers at the beginning of the gesture. Is that really how the pros do it? ;-) If so, I can't think of a way to make the gestures independent of screen size and resolution the data that we get from the touch positions is in pixels, not units of length. It's no big deal now, but it would be nice if people could still play my games, say, after I die and can't update the code for new devices.
My current idea is to set gesture differentiation differences based on iPhoneSettings.generation, and allow users to set their own preferred threshold in a tucked-away menu. Got any better ideas? :-)
Answer by Eric5h5 · Feb 07, 2011 at 07:02 PM
I would suggest normalizing the touch positions. For example (using mouse input to make this a bit more general):
private var screenWidth : float; private var screenHeight : float; private var ratio : float;
function Start () { screenWidth = Screen.width; screenHeight = Screen.height; ratio = screenWidth / screenHeight; }
function Update () { var normalizedMousePos = Vector2(Input.mousePosition.x / screenWidth * ratio, Input.mousePosition.y / screenHeight); }
That way the input coordinates are the same regardless of screen size.
I think that handles resolution independence fine for screens that are the same physical size. But going from iPhone to iPad, or from laptop trackpad to $$anonymous$$agic Trackpad (not possible yet I know), the distance at which a pinch becomes a rotate would become greater. It's not so bad on iOS right now, because I can painstakingly account for all options, but what if I'm interested in putting the game on more devices in the future? $$anonymous$$aybe it's just impossible to make a game that feels right for a whole bunch of devices of slightly different size?
Yeah, you'd also need to normalize for the physical screen size, something like mousePhysicalX = Input.mousePosition.x * screenWidthInInches / screenWidthInPixels. But then you need to deter$$anonymous$$e screenWidthInInches, from generation or whatever other info about the particular device you can find. But it does seem like the gestures ought to be scale-independent somehow, in which case Eric's suggestion makes sense.
Indeed, physical screen size is a somewhat different matter. I think going from iPod/iPhone -> iPad is different enough that ideally you need a different interface for many games and probably shouldn't just scale everything up. Some kind of "Screen.pixelsPerInch" property would be nice....
Answer by user-12680 (google) · May 12, 2011 at 05:08 AM
I have figured out the simplest solution and this is what Iphone SDK's Gesture recognizers do. pls go through this link.
http://ourinnovativemind.blogspot.com/2011/05/how-to-differentiate-between-rotation.html
Your answer
Follow this Question
Related Questions
How to identify each iOS device? 1 Answer
Xcode build crashes 0 Answers
Setting resolutions for iPad and iPhone 0 Answers
Grass Won't Show — Any Suggestions on the Cause? 2 Answers
Prepare Different Resolutions App Preview Videos for Apple Store 0 Answers