feat: Added Basic Camera

This commit is contained in:
2023-11-27 13:46:01 +03:00
parent 9b45bfa4fd
commit 9f4ad882e3
4 changed files with 139 additions and 2 deletions

View File

@@ -12,6 +12,7 @@ namespace Syntriax.Engine.Core;
public class GameManager : IEntity
{
public Action<GameManager>? OnCameraChanged { get; set; } = null;
public Action<IInitialize>? OnInitialized { get; set; } = null;
public Action<IInitialize>? OnFinalized { get; set; } = null;
public Action<IAssignable>? OnUnassigned { get; set; } = null;
@@ -24,6 +25,7 @@ public class GameManager : IEntity
private IStateEnable _stateEnable = null!;
private GameObjectFactory _gameObjectFactory = null!;
private bool _initialized = false;
private ICamera _camera = null!;
private GameObjectFactory GameObjectFactory
{
@@ -52,6 +54,19 @@ public class GameManager : IEntity
}
}
public ICamera Camera
{
get => _camera;
set
{
if (_camera == value)
return;
_camera = value;
OnCameraChanged?.Invoke(this);
}
}
public void RegisterGameObject(IGameObject gameObject)
{
if (_gameObjects.Contains(gameObject))
@@ -136,7 +151,7 @@ public class GameManager : IEntity
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Begin();
spriteBatch.Begin(SpriteSortMode.Deferred, transformMatrix: Camera.MatrixTransform);
foreach (var drawable in _drawables)
drawable.Draw(spriteBatch);