Game Development Community

iOS device orientation woes (portrait, touch y-transformation)

by Jeffrey Parker · in Torque 2D Beginner · 03/12/2013 (10:29 am) · 9 replies

We're putting together a game for iOS which displays only in portrait orientation. When the device is flat, the touch input works as expected, however when the device is raised (as you might hold a book), a modifier appears to be applied to the x/y coordinates sent with the up/down events (y -= ~250). It makes the touch elements a tad tricky to use, if not impossible (thanks to the relevant coordinates being offscreen).

(referencing the engine source)
This seems to be a result of a call to _iOSGameGetOrientation() within platformiOS/T2DView.mm which returns the orientation based on the devices position, not the orientation of the environment. This value is then used to determine whether or not the coordinates should be transformed by a call to UIDeviceOrientationIsPortrait(), and if it is, point Y is offset. This transformation appears to be the cause of the problems.

I've fixed the problem in my case by commenting out this portrait transformation, but it does seem that both the detection method and the transform are potentially faulty. Does anyone know what it was meant to achieve and how it might best be fixed?

#1
03/12/2013 (1:09 pm)
Ah, I know what's going on. I'll get this fixed and pushed to the development branch early tomorrow.
#2
06/12/2014 (11:24 pm)
Having this exact same issue with T2D 3.0
#3
06/13/2014 (7:56 am)
Really? I thought I had this resolved. What device are you using Josiah?
#4
06/13/2014 (9:34 am)
I don't see anything in the commit history from that time period related to iOS fixes - perhaps it got missed?
#5
06/13/2014 (9:43 am)
It's possible. I may have tried working in my fork and nuked it. If I can get technical details, it should be easy to track down and fix again.
#6
06/16/2014 (9:42 pm)
Running it on a iPhone 4 and iPad mini both have the same issue.
#7
10/07/2014 (5:43 am)
I got issue with portrait. The position of scene and touch is not correct.
#8
10/09/2014 (1:04 pm)
The way rotation works with view controllers in IOS8 was changed a lot. I wouldn't be surprised if the new problems were related to this. Speaking from experience I had to refactor a lot of code in a certain iTGB-based codebase in order to fix all the weird issues which cropped up.
#9
10/09/2014 (7:23 pm)
I test with IOS7, I fix it by set to fix portrait mode. And comment all screen oreintation test in script to not swap the width and height.

//if(%deviceScreenOrientation == $iOS::constant::Landscape)
if (true)
{
%x = $iOS::constant::iPhoneWidth * %scaleFactor;
%y = $iOS::constant::iPhoneHeight * %scaleFactor;
}
else
{
%x = $iOS::constant::iPhoneHeight * %scaleFactor;
%y = $iOS::constant::iPhoneWidth * %scaleFactor;
}