Pergunta

I am creating a game for Windows Phone 8 using Monogame. As shown in the picture, I want to control both the tank movement as well as its firing rate separately using two on screen controller.

However, I can only control one at a time. I can't move the tank and fire at the same time. I am using an input class where it manages the input. For each input I have

input.AddTouchGestureInput(playerMoveDrag, GestureType.FreeDrag,
        joystickMove.BoundingBoxRect);

input.AddTouchTapInput(playerFireTap, joystickFire.BoundingBoxRect, true);

So how do I detect two separate gestures (free drag for the D pad, and tap for the fire pad) simultaneously?

enter image description here

Foi útil?

Solução

I figured it out. Not as hard as I initially thought! In case anyone is in the same boat, here's my solution.

Instead of using gestures like FreeDrag, we read the raw touch data. Windows Phone 8 hardware seems to support up to 8 simultaneous touch points.

So part of my code that detect location of any touch on screen.

    public void GetTouchPoints()
    {
        TouchCollection touches = TouchPanel.GetState();

        for (int i = 0; i < touches.Count; i++)
        {
            Vector2 position = touches[i].Position;

            if (thumbstickMove.IsPointInside(position))
            {
                thumbstickMove.TouchLocation = position;
            }

            if (thumbstickFire.IsPointInside(position))
            {
                thumbstickFire.TouchLocation = position;
            }      
        }
    }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top