I am currently building a game using C#/XNA on VS2012 and on my code I want the user to touch an object and drag it vertically and horizontally without lifting the finger when switching to vertical or horizontal gesture. Here is a sample of my code:
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// Move the sprite by speed, scaled by elapsed time.
//shipPosition += shipSpeed;
// check whether gestures are available
while (TouchPanel.IsGestureAvailable)
{
// read the next gesture
GestureSample gesture = TouchPanel.ReadGesture();
// has the user tapped the screen?
switch (gesture.GestureType)
{
case GestureType.HorizontalDrag:
shipPosition += gesture.Delta;
break;
case GestureType.VerticalDrag:
shipPosition += gesture.Delta;
break;
}
}
// Make sure that the ship does not go out of bounds
shipPosition.X = MathHelper.Clamp(shipPosition.X, 35 / 2 , 765 + 35 / 2 - shipTexture.Width);
shipPosition.Y = MathHelper.Clamp(shipPosition.Y, 21 / 2, 451 + 21 / 2 - shipTexture.Height);
// TODO: Add your update logic here
base.Update(gameTime);
}
Can someone please advise? I saw somewhere that I have to use raw input touch but I would like to know how that works with drags.
Sounds like you need to use Touch Location instead
http://msdn.microsoft.com/en-us/library/ff434208.aspx
look under