Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I measure the time of a drag on my Windows Phone?
    primarykey
    data
    text
    <p>I want to measure the time of a drag. From the beginning(when the player touches the screen) to the end(when the player releases his finger from the screen). In addition, I want to measure the distance of the drag to calculate the velocity of the drag.</p> <p>But I always get the following two error messages.</p> <p>1)When I touche the screen I get this error message in the first line of the foreach loop:</p> <pre><code>GestureSample gs = TouchPanel.ReadGesture(); </code></pre> <p>An exception of type 'System.InvalidOperationException' occurred in Microsoft.Xna.Framework.Input.Touch.ni.dll but was not handled in user code If there is a handler for this exception, the program may be safely continued.</p> <p>2)The second error message is in this line:</p> <pre><code>DragTime = (float)(EndTime - StartTime); </code></pre> <p>Cannot convert type 'System.DateTime' to 'float'</p> <p>What is wrong? What can I do to fix the error messages?</p> <p>Here is my code:</p> <pre><code>public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Vector2 DragVelocity; TimeSpan StartTime; DateTime EndTime; float DragTime; Vector2 StartPoint, EndPoint, DragDistance; bool FirstTimePressed = 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.FreeDrag; } protected override void Update(GameTime gameTime) { TouchCollection touchCollection = TouchPanel.GetState(); foreach (TouchLocation tl in touchCollection) { GestureSample gs = TouchPanel.ReadGesture(); if (FirstTimePressed == true) { if ((tl.State == TouchLocationState.Pressed)) { StartTime = gs.Timestamp; StartPoint = gs.Delta; FirstTimePressed = false; } } if ((tl.State == TouchLocationState.Released)) { EndTime = DateTime.Now; DragTime = (float)(EndTime - StartTime); EndPoint = gs.Delta; DragDistance = EndPoint - StartPoint; DragVelocity = DragDistance / DragTime; FirstTimePressed = true; } } while (TouchPanel.IsGestureAvailable) { GestureSample gs = TouchPanel.ReadGesture(); switch (gs.GestureType) { case GestureType.FreeDrag: 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.
    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