我尝试在Monogame中获取触摸的坐标。 TouchPanel.DisplayWidth
和 TouchPanel.DisplayHeight
返回正确的值 (1919 x 1080)。但是,触摸位置的位置是720p分辨率内的坐标。代码如下:
TouchCollection touchCollection = TouchPanel.GetState();
foreach (TouchLocation tl in touchCollection)
{
if (tl.State == TouchLocationState.Pressed)
{
Vector2 position = tl.Position;
...
谁能告诉我为什么触摸屏分辨率与tl.position使用的分辨率不同?有没有办法解决这个问题?
我无法找到为什么会发生这种情况,但从简单的谷歌搜索中,我找到了解决这个问题的方法。
您可以使用缩放来获取接近真实的近似位置,因为您可能不需要手指触摸屏幕的位置的实际像素精度位置。
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));
}
我从这里复制的这段代码。
所以,我没有答案,但有一个解决方法(获取真实分辨率,创建将成为真实分辨率和 720p 分辨率之间的桥梁Vector2 scale
,并让用户使用缩放的 720p 分辨率接触点)。