More nullable fixes, make SetTransform a part of base Renderer.
This commit is contained in:
@@ -37,8 +37,8 @@ public class TestGame : Game
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
_renderer.Shutdown();
|
||||
_audioBackend.Shutdown();
|
||||
_renderer!.Shutdown();
|
||||
_audioBackend?.Shutdown();
|
||||
}
|
||||
|
||||
protected override void LoadResources()
|
||||
@@ -61,43 +61,37 @@ public class TestGame : Game
|
||||
|
||||
protected override void Ready()
|
||||
{
|
||||
_inputHandler.AddInputMapping("play", new InputAction[] { new KeyInputAction(KeyboardKey.Spacebar) });
|
||||
_inputHandler!.AddInputMapping("play", new InputAction[] { new KeyInputAction(KeyboardKey.Spacebar) });
|
||||
_inputHandler.AddInputMapping("sprint", new InputAction[] { new KeyInputAction(KeyboardKey.LeftShift) });
|
||||
|
||||
_scene.AddLayer("World", _worldLayer);
|
||||
_worldLayer.AddEntity(new World());
|
||||
_scene!.AddLayer("World", _worldLayer!);
|
||||
|
||||
_worldLayer!.AddEntity(new World());
|
||||
_worldLayer.AddEntity(new TestPlayer());
|
||||
|
||||
_scene.AddLayer("UI", _uiLayer!);
|
||||
|
||||
_scene.Start();
|
||||
}
|
||||
|
||||
protected override void Run()
|
||||
{
|
||||
while (_scene.ShouldRun)
|
||||
while (_scene!.ShouldRun)
|
||||
{
|
||||
_scene.Update();
|
||||
_scene.BeginDraw();
|
||||
_scene.EndDraw();
|
||||
|
||||
double frameTimeMs = _renderer.FrameTime * 1000f;
|
||||
|
||||
_renderer.SetTransform(Vector2.One * 32f, Vector2.Zero, 0f);
|
||||
|
||||
if (_font is not null)
|
||||
{
|
||||
_renderer.DrawText(_font, $"{frameTimeMs:0.0} ms", new Color(1f, 1f, 1f, 0.5f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Renderer _renderer;
|
||||
private Renderer? _renderer;
|
||||
private ResourceManager _resourceManager = new();
|
||||
private Sound? _testSound;
|
||||
private Font? _font;
|
||||
private FmodAudioBackend _audioBackend;
|
||||
private InputHandler _inputHandler;
|
||||
private Scene _scene;
|
||||
private FmodAudioBackend? _audioBackend;
|
||||
private InputHandler? _inputHandler;
|
||||
private Scene? _scene;
|
||||
|
||||
private UiLayer _uiLayer;
|
||||
private EntityLayer _worldLayer;
|
||||
private UiLayer? _uiLayer;
|
||||
private EntityLayer? _worldLayer;
|
||||
}
|
||||
@@ -14,7 +14,10 @@ public class TestPlayer : RectangleShape2d
|
||||
Current = true,
|
||||
};
|
||||
|
||||
Layer.AddEntity(_camera);
|
||||
if (Layer is not null)
|
||||
{
|
||||
Layer.AddEntity(_camera);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnUpdate(double dt)
|
||||
@@ -27,10 +30,13 @@ public class TestPlayer : RectangleShape2d
|
||||
var velocity = Input.GetInputDirection("left", "right", "up", "down") * _speed;
|
||||
Position += velocity * (float)dt;
|
||||
|
||||
_camera.Position = MathUtils.LerpVector2(_camera.Position, Position, dt * 5f);
|
||||
if (_camera is not null)
|
||||
{
|
||||
_camera.Position = MathUtils.LerpVector2(_camera.Position, Position, dt * 5f);
|
||||
}
|
||||
}
|
||||
|
||||
private Logger _logger = new(nameof(TestPlayer));
|
||||
private float _speed = 200f;
|
||||
private Camera2d _camera;
|
||||
private Camera2d? _camera;
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public class UiLayer : Layer
|
||||
protected override void OnUpdate(double dt)
|
||||
{
|
||||
base.OnUpdate(dt);
|
||||
// _textLabel.Text = $"{MathF.Round(1 / (float)dt)} FPS";
|
||||
if (Scene is null) return;
|
||||
_screenContainer.UpdateRect(Vector2.Zero, Scene.Renderer.WindowSize);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,8 @@ public class UiLayer : Layer
|
||||
|
||||
private void CreateUiElements()
|
||||
{
|
||||
_screenContainer = new Container();
|
||||
if (Scene is null) return;
|
||||
|
||||
_screenContainer.UpdateRect(Vector2.Zero, Scene.Renderer.WindowSize);
|
||||
|
||||
var style = new PanelStyle()
|
||||
@@ -56,7 +57,7 @@ public class UiLayer : Layer
|
||||
|
||||
var exampleText = new TextLabel()
|
||||
{
|
||||
Font = _defaultFont,
|
||||
Font = _defaultFont!,
|
||||
FontSize = 20,
|
||||
Text = "This Panel will occupy 50% of the screen.\nThis text in particular is inside a panel with an absolute margin of 16px.\nHow cool is that?"
|
||||
};
|
||||
@@ -89,10 +90,9 @@ public class UiLayer : Layer
|
||||
}
|
||||
|
||||
|
||||
private Font _defaultFont;
|
||||
private Container _screenContainer;
|
||||
private Panel _panel, _contentPanel;
|
||||
private TextLabel _textLabel;
|
||||
private Font? _defaultFont;
|
||||
private Container _screenContainer = new();
|
||||
private Panel? _panel;
|
||||
|
||||
private Logger _logger = new(nameof(UiLayer));
|
||||
}
|
||||
Reference in New Issue
Block a user