create camera script to report it's current viewport via the event bus
This commit is contained in:
parent
6ffb2a58d0
commit
96a64077bf
20
scenes/player/Camera.cs
Normal file
20
scenes/player/Camera.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
@ -14,4 +14,6 @@ public sealed class Event : Node
|
|||||||
delegate void PlayerTouched();
|
delegate void PlayerTouched();
|
||||||
[Signal]
|
[Signal]
|
||||||
delegate void DebugState(string state);
|
delegate void DebugState(string state);
|
||||||
|
[Signal]
|
||||||
|
delegate void CameraView(Rect2 rect);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user