[SOLVED] Help Demo Camera LookAt

Does anyone know a simple way to implement the “camera.LookAt” or a form of camera accompanies the position of the character as it moves in the Demo.Platformer
MonoGame Extended Demo Platformer

Only center the camera position in the initial position

public class GameScreen : Screen
        public GameScreen(IServiceProvider services, GraphicsDevice graphicsDevice, GameWindow window)
            Services = services;
            GraphicsDevice = graphicsDevice;
            Window = window;

        private Camera2D _camera;
        private TiledMap _tiledMap;
        private IMapRenderer _mapRenderer;
        private EntityComponentSystem _entityComponentSystem;
        private EntityFactory _entityFactory;

        public IServiceProvider Services { get; }
        public ContentManager Content { get; private set; }
        public GraphicsDevice GraphicsDevice { get; }
        public GameWindow Window { get; }

        public override void Initialize()

            Content = new ContentManager(Services, "Content");

        public override void LoadContent()

            var viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
            _camera = new Camera2D(viewportAdapter);

            _tiledMap = Content.Load<TiledMap>("level-1");
            _mapRenderer = new FullMapRenderer(GraphicsDevice, new MapRendererConfig {DrawObjectLayers = false});

            _entityComponentSystem = new EntityComponentSystem();
            _entityFactory = new EntityFactory(_entityComponentSystem, Content);

            var service = new TiledObjectToEntityService(_entityFactory);
            var spawnPoint = _tiledMap.GetObjectGroup("entities").Objects.Single(i => i.Type == "Spawn").Position;

            _entityComponentSystem.RegisterSystem(new PlayerMovementSystem());
            _entityComponentSystem.RegisterSystem(new EnemyMovementSystem());
            _entityComponentSystem.RegisterSystem(new CharacterStateSystem(_entityFactory, spawnPoint));
            _entityComponentSystem.RegisterSystem(new BasicCollisionSystem(gravity: new Vector2(0, 1150)));
            _entityComponentSystem.RegisterSystem(new ParticleEmitterSystem());
            _entityComponentSystem.RegisterSystem(new AnimatedSpriteSystem());
            _entityComponentSystem.RegisterSystem(new SpriteBatchSystem(GraphicsDevice, _camera) { SamplerState = SamplerState.PointClamp });


        public override void Update(GameTime gameTime)


        public override void Draw(GameTime gameTime)

            var viewMatrix = _camera.GetViewMatrix();



I’m not entirely certain I understand your question but I think you’re asking how you would get the camera to follow the player as he moves.

There’s probably a number of different ways to approach this problem. In an entity component system might create some sort of CameraFollowSystem similar to how the PlayerMovementSystem works. Although, the design is really up to you depending on how you want your game to work.

The absolute simplest way to get this working is to pass the _camera into the constructor of the PlayerMovementSystem like so:

_entityComponentSystem.RegisterSystem(new PlayerMovementSystem(_camera));

Inside the PlayerMovementSystem you’d change the constructor to look like this:

    private readonly Camera2D _camera;

    public PlayerMovementSystem(Camera2D camera)
        _camera = camera;

Then finally in the Update method you add your _camera.LookAt line:

    public override void Update(GameTime gameTime)
        if(_playerEntity == null)


And that’s it.

At this point, the camera will follow the player in a kind of rough prototype kind of way. You’d have to think about how to deal with the camera going outside the bounds of the map and maybe you’d want to implement some sort of tweening for camera movement perhaps.

Thank you was exactly that worked perfectly :smiley: