How to fix Monogame WP8 Touch Position bug?
Posted
by
Moses Aprico
on Game Development
See other posts from Game Development
or by Moses Aprico
Published on 2013-05-31T16:34:36Z
Indexed on
2013/11/09
4:19 UTC
Read the original article
Hit count: 1516
Normally below code will result in X:Infinity, Y:Infinity
TouchCollection touchState = TouchPanel.GetState();
foreach (TouchLocation t in touchState)
{
if (t.State == TouchLocationState.Pressed)
{
vb.ButtonTouched((int)t.Position.X, (int)t.Position.Y);
}
}
Then, I followed this https://github.com/mono/MonoGame/issues/1046 and added below code at the first line in update method. (I still don't know how it's worked, but it fixed the problem)
if (_firstUpdate)
{
typeof(Microsoft.Xna.Framework.Input.Touch.TouchPanel).GetField("_touchScale",System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static).SetValue(null, Vector2.One);
_firstUpdate = false;
}
And then, when I randomly testing something, there are several area that won't read the user touch.
The tile with the purple dude is the area which won't receive user input (It don't even detect "Pressed", the TouchCollection.Count = 0)
Any idea how to fix this?
UPDATE 1 : The second attempt in recompiling
The difference is weird. Dunno why the consistent clickable area is just 2/3 area to the left
UPDATE 2 : After trying to rotate to landscape and back to portrait to randomly testing, then the outcome become :
© Game Development or respective owner