Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I were you I would do it this way- when user presses the screen for the first time, set a global variable <code>TimeSpan time</code> to <code>TimeSpan.Zero</code>. Then, on every update, add <code>gameTime.ElapsedRealTime</code> to time variable. When user releases, your can get your time from time variable, it's easy. To get seconds just use: <code>time.totalSeconds</code>.</p> <p>I've modified your code a little, here you go:</p> <pre><code>public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; float DragVelocity, DragDistance, DragTime; TimeSpan time; Vector2 StartPoint, EndPoint; bool isThisFirstTime = true; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; TargetElapsedTime = TimeSpan.FromTicks(333333); InactiveSleepTime = TimeSpan.FromSeconds(1); } protected override void Initialize() { base.Initialize(); } protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); TouchPanel.EnabledGestures = GestureType.DragComplete | GestureType.FreeDrag; } protected override void Update(GameTime gameTime) { while (TouchPanel.IsGestureAvailable) { GestureSample gs = TouchPanel.ReadGesture(); switch (gs.GestureType) { case GestureType.FreeDrag: if (isThisFirstTime == true) { time = TimeSpan.Zero; StartPoint = gs.Position; isThisFirstTime = false; } else { EndPoint = gs.Position; time += gameTime.ElapsedGameTime; } break; case GestureType.DragComplete: isThisFirstTime = true; DragTime = (float) time.TotalSeconds; DragDistance = Vector2.Distance(StartPoint, EndPoint); DragVelocity = DragDistance / DragTime; break; } } base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); base.Draw(gameTime); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload