2D Toolkit Forum

2D Toolkit => Support => Topic started by: Busson on July 24, 2013, 02:19:27 am

Title: Landscape Orientation Problem - WP8 Project
Post by: Busson on July 24, 2013, 02:19:27 am
Hello,

I configured the orientation of my project as landscape, but tk2dcamera remains in portrait orientation . See the image below:

With the camera's Unity works. This project is running on a Windows Phone 8.

(http://img33.imageshack.us/img33/1416/ihwr.jpg)
Title: Re: Landscape Orientation Problem - WP8 Project
Post by: idloco on July 24, 2013, 05:19:33 am
I´m having the same issue with exporting to Windows Phone 8  :(
Title: Re: Landscape Orientation Problem - WP8 Project
Post by: Busson on July 24, 2013, 01:48:46 pm
 :-\ works in portrait mode, but not landscape

(http://img838.imageshack.us/img838/7396/soe0.jpg)

(http://img819.imageshack.us/img819/7308/7zis.jpg)
Title: Re: Landscape Orientation Problem - WP8 Project
Post by: nikhilf on July 25, 2013, 11:38:28 am
I am facing the same issue.
I tried to add a Unity Camera on top of the tk2dcamera after which works fine.
But I want it to work with the tk2dcamera itself.
Title: Re: Landscape Orientation Problem - WP8 Project
Post by: unikronsoftware on July 25, 2013, 11:40:14 am
After a bit of investigation, it looks like this is a problem specific to WP8 - Unity is performing the rotation by modifying the projection matrix :(
You can work around it by adding this in tk2dCamera:

2DTOolkit 1.9x / 2.0 -
Code: [Select]
[b]if (Application.platform == RuntimePlatform.WP8Player &&
    (Screen.orientation == ScreenOrientation.LandscapeLeft || Screen.orientation == ScreenOrientation.LandscapeRight))
   {
    float angle = (Input.deviceOrientation == DeviceOrientation.LandscapeRight) ? 90.0f : -90.0f;
    Matrix4x4 m2 = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0, 0, angle), Vector3.one);
    m = m2 * m;
   }
[/b]
                if (mainCamera.projectionMatrix != m) {
mainCamera.projectionMatrix = m;
}

2DToolkit 2.1 -
Code: [Select]
[b]if (Application.platform == RuntimePlatform.WP8Player &&
    (Screen.orientation == ScreenOrientation.LandscapeLeft || Screen.orientation == ScreenOrientation.LandscapeRight))
   {
    float angle = (Input.deviceOrientation == DeviceOrientation.LandscapeRight) ? 90.0f : -90.0f;
    Matrix4x4 m2 = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0, 0, angle), Vector3.one);
    m = m2 * m;
   }
[/b]
if (unityCamera.projectionMatrix != m) {
unityCamera.projectionMatrix = m;
}


This doesn't handle all the possibilities properly, as there is no way to find out what the user has selected in the build settings at runtime, but will be a good place to start.
Title: Re: Landscape Orientation Problem - WP8 Project
Post by: nikhilf on July 25, 2013, 01:33:59 pm
The fix works like a charm!
Thanks for the quick response.  :)
Title: Re: Landscape Orientation Problem - WP8 Project
Post by: Busson on July 25, 2013, 03:35:39 pm
worked  :D

thank you!
Title: Re: Landscape Orientation Problem - WP8 Project
Post by: cesarpo on August 17, 2013, 04:40:21 am
 I had the same problem. and adding this code fixes the error, but still the tk2dCamera responds to the Portrait orientation, how can I do to only support Landscape modes?

edit

I had to edit the MainPage.xaml and set the SupportedOrientations="Landscape" attribute. This seems to be independent of the player configuration in the project settings :/

Code: [Select]
    Foreground="{StaticResource PhoneForegroundBrush}" Orientation="Landscape" SupportedOrientations="Landscape" BackKeyPress="PhoneApplicationPage_BackKeyPress" OrientationChanged="PhoneApplicationPage_OrientationChanged">
Title: Re: Landscape Orientation Problem - WP8 Project
Post by: unikronsoftware on August 17, 2013, 12:42:22 pm
I forgot to post an updated fix. Input.screenOrientation should be Screen.orientation instead. This respects the configuration in Unity. I've updated the code above with the required changes.