0

I try to get the coordinates of a touch in Monogame. TouchPanel.DisplayWidth and TouchPanel.DisplayHeight return the right values (1919 x 1080). However the position of the touchLocation is a coordinate within a 720p resolution. Here's the code:

TouchCollection touchCollection = TouchPanel.GetState();
    foreach (TouchLocation tl in touchCollection)
    {
        if (tl.State == TouchLocationState.Pressed)
        {
            Vector2 position = tl.Position;
            ...

Can anybody tell me why the TouchPanel resolution is not the same resolution the tl.position uses? Is there a way to fix this?

paste
  • 350
  • 1
  • 10

1 Answers1

0

I was unable to find why this is happening, but from simple google search, I've found out the way to cope with this problem.

You can use scaling to get the approximate position, close to real, since you probably won't need the real-pixel-precision position of where the finger is touching the screen.

for (int i = 0; i < touchCollection.Count; i++)
{
    InputPoints.Add(new Vector2
    (touchCollection[i].Position.X / Game1.ScalingFactor.X,
    touchCollection[i].Position.Y / Game1.ScalingFactor.Y));
}

This code I copied from here.

So, I don't have the answer, but a workaround (get the real resolution, create Vector2 scale that will be the bridge between the real resolution and 720p resolution, and get users touch points with scaled 720p resolution).

Monset
  • 648
  • 5
  • 25