I have two buttons in my MonoGame Android game, the Move button, and the Aim button. Both have their own update, with their own touch input code. But only the first one is done, the one after is ignored?
I heard that the problem is that the touch code removes the input when it has been handled, so the next update won’t run. So now they have the same input code… Which works not quite perfect at all.
Code:
public void HandleTouchInput()
{
while (TouchPanel.IsGestureAvailable)
{
GestureSample gesture = TouchPanel.ReadGesture();
#region MoveJoy
if ((gesture.Position - new Vector2(moveJoystick.x * ((int)(GameRoot.ScreenSize.X / GameRoot.VirtualScreenSize.X)), moveJoystick.y * ((int)(GameRoot.ScreenSize.Y / GameRoot.VirtualScreenSize.Y)))).Length() < Art.Joystick.Width / 2) // 160
{
moveJoystick.fingerIsDown = true;
moveJoystick.knob.x = (int)gesture.Position.X * ((int)(GameRoot.ScreenSize.X / GameRoot.VirtualScreenSize.X));
moveJoystick.knob.y = (int)gesture.Position.Y ;
moveJoystick.direction.X = moveJoystick.knob.x - moveJoystick.x; // To calculate we need the position _relative_ to the centre of the joystick.
moveJoystick.direction.Y = moveJoystick.knob.y - moveJoystick.y;
}
else
moveJoystick.fingerIsDown = false;
#endregion
#region AimJoy
if ((gesture.Position - new Vector2(aimJoystick.x, aimJoystick.y)).Length() < 180)
{
aimJoystick.fingerIsDown = true;
aimJoystick.knob.x = (int)gesture.Position.X;
aimJoystick.knob.y = (int)gesture.Position.Y;
aimJoystick.direction.X = aimJoystick.knob.x - aimJoystick.x;// + GameRoot.ScreenSize.X - Art.Joystick.Width; // To calculate we need the position _relative_ to the centre of the joystick.
aimJoystick.direction.Y = aimJoystick.knob.y - aimJoystick.y;
}
else
aimJoystick.fingerIsDown = false;
#endregion
}
}