0

I'm creating a Universal (Win 8.1 + Win Phone 8.1) app using C# / Monogame (VS 2013). I'm using MonoGame v3.4.

In my game1.cs initialization code, I set:

TouchPanel.DisplayWidth = _drawState.ScreenBounds.Width;
TouchPanel.DisplayHeight = _drawState.ScreenBounds.Height;

So that touch input is consistent to my game screen size (_drawState.ScreenBounds is a Rectangle containing the dimensions of my virtual screen size).

My game is set to support only portraint orientations: I have picked only the portrait and portrait-flipped orientations in the Package.appxmanifest files for both target (Win and WinPhone), and I have set this in the game1.cs Init method:

graphics.SupportedOrientations = DisplayOrientation.Portrait |
DisplayOrientation.PortraitDown

Testing the game on the Win 8.1 Simulator and on a real Win 8.1 tablet, I found out that after an orientation change (btw, the Simulator rotates and crops the game field, whereas the real device, as expected, keeps the portrait aspect), the TouchPanel has wrong dimensions - it resets to the actual screen dimensions, and so all my touches are off.

This only happens on the Win8.1 target - the Win Phone targets works as intended.

Any ideas?

EDIT: Since I couldn't find what was going on, I just decided to subscribe to the size changed event and set the TouchPanel.DisplayWidth and TouchPanel.DisplayHeight variables:

this.Window.AllowUserResizing = true;
this.Window.ClientSizeChanged += Window_ClientSizeChanged;

The Window_ClientSizeChanged method is called on the Simulator, but not on the real device.

I tried with:

_window = Windows.UI.Core.CoreWindow.GetForCurrentThread();
_window.SizeChanged += _window_SizeChanged;

Same thing - called on the simulator, not on the device.

Spyros P.
  • 296
  • 3
  • 14

1 Answers1

0

Not being able to find a solution to this problem, I just decided to handle the touch input differently; instead of setting the TouchPanel.DisplayWidth & Height, I decided to convert the touch (and mouse) position to the virtual screen coordinates using a simple function:

ScreenYScale = GraphicsDevice.PresentationParameters.BackBufferHeight / 1920.0f;

public Vector2 TranslateCoords(Vector2 coords)
{
    return new Vector2(coords.X / ScreenYScale, coords.Y / ScreenYScale);
}
Spyros P.
  • 296
  • 3
  • 14
  • Hey Sypros..Could you please tell me how did use this codes in your game.I mean you now have a new vector,how you related this to touchpanel. – uncle_scrooge Oct 01 '15 at 04:43