I am porting a game over to a XNA 4.0 WP7 project but am having some problems with controls. I am using the accelerometer to control movement but sometimes the ship will completely skip to another area of the screen. I have the code below for the controls.
Accelerometer _motion;
Vector2 accelReading = new Vector2();
private float speed = 50.0f;
//Initialize
_motion = new Accelerometer();
_motion.ReadingChanged += new EventHandler<AccelerometerReadingEventArgs>(AccelerometerReadingChanged);
_motion.Start();
//Method for Changed Readings
public void AccelerometerReadingChanged(object sender, AccelerometerReadingEventArgs e)
{
accelReading.X = (float)e.X;
accelReading.Y = (float)e.Y;
vel.X = accelReading.Y * speed;
vel.Y = accelReading.X * speed;
}
//Update
float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
pos += vel * elapsed;
vel *= 1 - elapsed;
ReadingChanged
event is marked deprecated in WP 7.1 that's there was some reason and it might be reading errors use CurrentValueChanged
.
If that do not help try WP7 using Motion
class it is more accure
http://msdn.microsoft.com/en-us/library/microsoft.devices.sensors.motion(v=vs.92).aspx