   input with XNA4.0 CTP in phone7 emulator
  Hey all,Running into an "input emulation" problem...trying to get a small project ported over to XNA 4.0 CTP and the code I've found on channel9 doesn't seem to work..#if WINDOWS_PHONE   //Input Members   AccelerometerReading accelState;   TouchCollection touchState;#endif//snip//initialize the touch emulation#if WINDOWS_PHONE  if (AccelerometerSensor.Default.State == SensorState.Ready)  { AccelerometerSensor.Default.ReadingChanged += (s, e) => {accelState = e.Value.Value; }; AccelerometerSensor.Default.Start();  }#endif//snip#if WINDOWS_PHONE  //if (input == null)  //throw new ArgumentNullException("input");  touchState = TouchPanel.GetState();  bool buttonTouched = false;  //interpret touch screen presses  foreach (TouchLocation location in touchState)  { switch (location.State) {case TouchLocationState.Pressed:    buttonTouched = true;    break;case TouchLocationState.Moved:    break;case TouchLocationState.Released:    break; }  }  float movement = 0.0f;  if (Math.Abs(accelState.X) > 0.10f)  { if (accelState.X > 0.0f)movement = 1.0f; elsemovement = -1.0f;  } //update player's position based on movement and buttonTouched, etc.#endifIt doesn't seem to register properly...my mouse clicks go unansweredany ideas? thanks!   
  Hi,you might want to try this instead:  float movement = 0.0f;  //interpret touch screen presses  foreach (TouchLocation location in touchState)  { switch (location.State) {case TouchLocationState.Pressed:    buttonTouched = true;    break;case TouchLocationState.Moved:    TouchLocation previousLocation;    if (location.TryGetPreviousLocation(out previousLocation))    {   // TODO: Account for orientation ?   movement = (location.Position.Y - previousLocation.Position.Y);    }    break;case TouchLocationState.Released:    break; }  }That's a simple way of doing it, but you might want to scale down/up the movement value.For anything more complex you will want to use the TouchLocationState.Released event as well, this is just a quick example.Also if you want to do like some iPhone games and assign an area of the screen to a control, you could do something like this:   /// <summary>   /// Checks if position is within a given rectangle (usually for touchscreen positioning when it comes to input)   /// </summary>   /// <param name="touchPos">The position of the touch (or any position, for that matter)</param>   /// <param name="buttonRectangle">The rectangle, or the button that user is aiming to touch</param>   /// <returns></returns>   public bool isPositionInRectangle(Vector2 touchPos, Rectangle buttonRectangle)   {  if (touchPos.X > buttonRectangle.Left && touchPos.X < buttonRectangle.Right)  { if (touchPos.Y > buttonRectangle.Top && touchPos.Y < buttonRectangle.Bottom) {return true; }  }  return false;   }...case TouchLocationState.Moved:   if (isPositionInRectangle(location.Position, new Rectangle(140, 0, 140, 150)))   {  // Move left  movement = -1.0f;  // System.Diagnostics.Debug.WriteLine("Touching left-movement (normal), right-movement (upside-down)");   }Regards,Julien   ;  A couple minor, but potentially useful, notes:- You don't have to #ifdef TouchCollection or any of our touch APIs; in XNA GS 4.0 they are cross platform and work on Windows Phone and Windows 7.- If you only care about single touch, you can use the Mouse API on both Windows and Windows Phone. We map a primary touch point on the phone to be the mouse. Basically you're able to get the X/Y position and LeftButton will be pressed in a MouseState if you have a touch on the screen. Unless you want to use multitouch, I recommend this approach as it keeps your code much simpler.   