feat: Camera Reset
This commit is contained in:
		@@ -9,6 +9,8 @@ public class CameraController : BehaviourOverride
 | 
			
		||||
    private MonoGameCameraBehaviour cameraBehaviour = null!;
 | 
			
		||||
    private IButtonInputs<Keys> buttonInputs = null!;
 | 
			
		||||
 | 
			
		||||
    private float defaultZoomLevel = 1f;
 | 
			
		||||
 | 
			
		||||
    protected override void OnFirstActiveFrame()
 | 
			
		||||
    {
 | 
			
		||||
        if (BehaviourController.TryGetBehaviour(out MonoGameCameraBehaviour? foundCameraBehaviour))
 | 
			
		||||
@@ -21,6 +23,7 @@ public class CameraController : BehaviourOverride
 | 
			
		||||
 | 
			
		||||
        buttonInputs ??= BehaviourController.AddBehaviour<KeyboardInputsBehaviour>();
 | 
			
		||||
        buttonInputs.RegisterOnPress(Keys.F, SwitchToFullScreen);
 | 
			
		||||
        buttonInputs.RegisterOnPress(Keys.R, ResetCamera);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected override void OnUpdate()
 | 
			
		||||
@@ -49,7 +52,15 @@ public class CameraController : BehaviourOverride
 | 
			
		||||
 | 
			
		||||
        float previousScreenSize = Math.Sqrt(Math.Pow(cameraBehaviour.Viewport.Width, 2f) + Math.Pow(cameraBehaviour.Viewport.Height, 2f));
 | 
			
		||||
        float currentScreenSize = Math.Sqrt(Math.Pow(Game1.graphics.GraphicsDevice.Viewport.Width, 2f) + Math.Pow(Game1.graphics.GraphicsDevice.Viewport.Height, 2f));
 | 
			
		||||
        defaultZoomLevel /= previousScreenSize / currentScreenSize;
 | 
			
		||||
        cameraBehaviour.Zoom /= previousScreenSize / currentScreenSize;
 | 
			
		||||
        cameraBehaviour.Viewport = Game1.graphics.GraphicsDevice.Viewport;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void ResetCamera(IButtonInputs<Keys> inputs, Keys keys)
 | 
			
		||||
    {
 | 
			
		||||
        cameraBehaviour.Zoom = defaultZoomLevel;
 | 
			
		||||
        Transform.Position = Vector2D.Zero;
 | 
			
		||||
        Transform.Rotation = 0f;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user