0
\$\begingroup\$

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 actual screenshoot

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

enter image description here

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 :

enter image description here

\$\endgroup\$
5
  • \$\begingroup\$ Are you able to test on a real device? It's possible the emulation is flawed. (Though you clearly have code problems as well.) \$\endgroup\$ Commented Jun 1, 2013 at 16:51
  • \$\begingroup\$ I'm afraid not. I don't own WP8 yet. My teacher tries the code above in monogame non-WP8 and it worked well. I think the problem is because the ClientBound is invalid. But I doesn't know how to fix it. monogame.codeplex.com/discussions/431035 \$\endgroup\$ Commented Jun 1, 2013 at 18:15
  • \$\begingroup\$ Did you solve the issue of certain areas not responding to touch? I am still having this problem. \$\endgroup\$
    – dChimento
    Commented Nov 7, 2013 at 20:19
  • \$\begingroup\$ I've post an answer to this, just now. EDIT : Ouch sorry I answered wrong problem. I'll fix it \$\endgroup\$ Commented Nov 9, 2013 at 2:55
  • \$\begingroup\$ I've posted the correct one recently \$\endgroup\$ Commented Nov 9, 2013 at 3:48

1 Answer 1

0
\$\begingroup\$

There are 3 changes I made to solve this :

1) Make some changes in GamePage.xaml.

2) Using the different way to use TouchPanel.

3) Using the monogame-develop source code as my project reference instead of the installed one (3.0.1).

#

1) Make some changes in GamePage.xaml

Normally, when you are first created a monogame project, there are these codes in the GamePage.xaml.

<DrawingSurfaceBackgroundGrid x:Name="XnaSurface" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
        <TextBlock Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
        <TextBlock Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
    </StackPanel>

    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

    </Grid>
</DrawingSurfaceBackgroundGrid>

....Change it into :

<Grid x:Name="LayoutRoot">
    <MediaElement />
    <DrawingSurface x:Name="XnaSurface" />
</Grid>

2) Using the different way to use TouchPanel.

First step, is to add enabled gestures you want in your game. Set it in your Game1.cs constructor (TouchPanel.EnabledGestures)

Game1()
{
    _graphics = new GraphicsDeviceManager(this);
    Content.RootDirectory = "Content";
    TouchPanel.EnabledGestures = GestureType.FreeDrag | GestureType.Tap;
}

You can add in extra enabled gestures by adding | Gesture.DoubleTap (for example), etc.

Second step is to use below code to detect your touch (put it in your update method)

public override void Update(GameTime gameTime)
{
    while (TouchPanel.IsGestureAvailable)
    {
        GestureSample gesture = TouchPanel.ReadGesture();
        switch (gesture.GestureType)
        {
            case GestureType.Tap:
            {
                //what to do if a tap is detected??
            }break;
            case GestureType.FreeDrag:
            {
                //what to do if a freedrag is detected??
            }break
            //and so on, depends on your enabledgestures..
        }
   }
}

3) Using the monogame-develop source code as my project reference instead of the installed one (3.0.1).

There is some bugs in MonoGame 3.0.1, so after I read & asked several times at the monogame forum, it's said that the "developed" monogame source code, is already corrected some problems (including mine). But since they hasn't released the "install" version, I need to use it directly from the source code. This is how :

https://monogame.codeplex.com/discussions/453170

That's my question thread, and it already answered (and solved) clearly.

#

Hope those helps.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .