Sup guys (novice gamedev building first game :D) im struggling to drag around a very basic sprite. Done a bit of research and regardless of whether i use the GestureType.FreeDrag enum or just use the TouchCollection implementation - im not 100% able to get the desired effect.
With both implementations for some weird reason im not able to drag the sprite back from its starting position (so in other words i can move positively along the x and y axis but never negatively).
Any feedback is welcome - thanks.
Note: The IsPressed bool is just so i can snap back to the position the sprite was in
public override void Update()
{
if (TouchCollection.Count > 0)
{
foreach (var touch in TouchCollection)
{
if (SpriteSurface.Contains(touch.Position))
{
IsPressed = true;
XPosition = touch.Position.X;
YPosition = touch.Position.Y;
}
}
}
if (TouchCollection.Count == 0)
{
IsPressed = false;
}
}
Alternative implementation
public override void Update()
{
while (TouchPanel.IsGestureAvailable)
{
var touch = TouchPanel.ReadGesture();
if (SpriteSurface.Contains(touch.Position))
{
IsPressed = true;
if (touch.GestureType == GestureType.FreeDrag)
{
if (touch.Delta.X >= 0 || touch.Delta.X < 0)
{
XPosition = touch.Position.X;
}
if (touch.Delta.Y >= 0 || touch.Delta.Y < 0)
{
YPosition = touch.Position.Y;
}
}
}
}
if (TouchCollection.Count == 0)
{
IsPressed = false;
}
}