locked
[UWP] Swinging the bat - detecting position of pointing device RRS feed

  • Question

  • Hi!

    I would like to create a simple Alien Invader game using XAML and Canvas control. So far I only got the ball to bounce off the walls. But how do I get to move the bat (to change direction of the ball). I guess there is an event to track the position of the pointing device (mouse or finger). I only have found the event PointerMoved, but I can't find any X coordinates tied to this event  (if the user is moving the bat to the right or to the left). Some clue to get me a step further?

    Thanks, Sigurd F

    Wednesday, May 4, 2016 9:30 PM

Answers

  • Hi Sigurd F,

    You could use GetCurrentPointto get current pointer position. For example:

    Xaml:
    <Canvas x:Name="canvas1" PointerMoved="canvas1_PointerMoved" Background="Green" />

    c#:
            private void canvas1_PointerMoved(object sender, PointerRoutedEventArgs e)
            {
                var currentPoint = e.GetCurrentPoint(canvas1);
                Debug.WriteLine(DateTime.Now.ToString() + ": x=" + currentPoint.Position.X + ", y=" + currentPoint.Position.Y);
            }

    Output:



    Best Regards,
    Leon Guang



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, May 5, 2016 7:03 AM