移动对象时,相机不会保持在对象的中心。
我似乎无法找到错误。请帮忙。
最初的-
`ConvertUnits.ToDisplayUnits(body.Position)-(Camera._screenCenter- Camera._cameraPosition)`
这将返回零。
一些动作后,它改变了。
我正在使用 Farseer Physics Engine 3.5 并用力移动身体。
body.ApplyForce();
这是我的相机课-
class Camera
{
private static Matrix _view;
public static Vector2 _cameraPosition;
public static Vector2 _screenCenter;
private static float _zoom;
private static float _rotation;
public static void Load(GraphicsDeviceManager _graphics)
{
_view = Matrix.Identity;
_cameraPosition = Vector2.Zero;
_screenCenter = new Vector2(_graphics.GraphicsDevice.Viewport.Width / 2f, _graphics.GraphicsDevice.Viewport.Height / 2f);
_rotation = 0f;
_zoom = 1.0f;
}
public static void HandleInput(KeyboardState state)
{
if (state.IsKeyDown(Keys.Add) && _zoom < 1.0f)
_zoom += 0.1f;
if (state.IsKeyDown(Keys.Subtract) && _zoom > 0.1f)
_zoom -= 0.1f;
Update();
}
public static void Update()
{
_view = Matrix.CreateTranslation(
new Vector3(_cameraPosition - _screenCenter, 0f)) *
Matrix.CreateRotationZ(_rotation) *
Matrix.CreateScale(new Vector3(_zoom, _zoom, 1)) *
Matrix.CreateTranslation(new Vector3(_screenCenter, 0f));
}
public static void Follow(Body body)
{
if (body != null)
_cameraPosition = _screenCenter - ConvertUnits.ToDisplayUnits(body.Position);
}
public static Matrix getView()
{
return _view;
}
}