1

When moving the object around, the camera doesn't remain centered on the object.

I can't seem to locate the bug. Please help.

Initial-

`ConvertUnits.ToDisplayUnits(body.Position)-(Camera._screenCenter- Camera._cameraPosition)`

This returns zero.

After some movement it changes. Initial State

After moving the body

I am using Farseer Physics Engine 3.5 and moving the body using force.

body.ApplyForce();

This is my Camera Class-

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;
        }
    }

Debug Info

4

1 に答える 1