0

我正在将游戏移植到 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;
4

1 回答 1

0

ReadingChanged事件在 WP 7.1 中被标记为已弃用,这是有原因的,它可能是读取错误使用CurrentValueChanged.

如果这无助于使用Motion类尝试 WP7,则更准确

http://msdn.microsoft.com/en-us/library/microsoft.devices.sensors.motion(v=vs.92).aspx

于 2012-08-12T14:45:58.850 回答