create camera script to report it's current viewport via the event bus

This commit is contained in:
Chris Cromer 2022-11-21 01:42:57 -03:00
parent 6ffb2a58d0
commit 96a64077bf
2 changed files with 22 additions and 0 deletions

20
scenes/player/Camera.cs Normal file
View File

@ -0,0 +1,20 @@
using Godot;
using System;
public class Camera : Camera2D
{
private Event _event;
public override void _Ready()
{
_event = GetNode<Event>("/root/Event");
}
public override void _PhysicsProcess(float delta)
{
var rect = GetViewportRect();
var owner = (Node2D) Owner;
rect.Position = owner.Position - rect.Size / 2;
_event.EmitSignal("CameraView", rect);
}
}

View File

@ -14,4 +14,6 @@ public sealed class Event : Node
delegate void PlayerTouched();
[Signal]
delegate void DebugState(string state);
[Signal]
delegate void CameraView(Rect2 rect);
}