我正在将游戏移植到 XNA 4.0 WP7 项目,但在控制方面遇到了一些问题。我正在使用加速度计来控制运动,但有时船会完全跳到屏幕的另一个区域。我有下面的控件代码。
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;