-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNormalizedCamera.cs
More file actions
59 lines (51 loc) · 1.75 KB
/
NormalizedCamera.cs
File metadata and controls
59 lines (51 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using Godot;
using System;
public partial class NormalizedCamera : Camera2D
{
public enum Mode : int {
Fit = 0,
Fill = 1,
Stretch = 2
}
[Export]
public int unitsH = 1920;
[Export]
public int unitsV = 1080;
[Export]
public Mode mode = Mode.Fit;
[Export]
public Room currentRoom;
// Called when the node enters the scene tree for the first time.
public override void _Ready() {
var temp = currentRoom;
currentRoom = null;
TransitionToRoom(currentRoom);
currentRoom = temp;
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta) {
//var size = new Vector2I(192, 108);
//var zh = (float)size.X / unitsH;
//var zv = (float)size.Y / unitsV;
//Zoom = (mode) switch {
// Mode.Fill => new(Mathf.Max(zh, zv), Mathf.Max(zh, zv)),
// Mode.Fit => new(Mathf.Min(zh, zv), Mathf.Min(zh, zv)),
// Mode.Stretch => new(zh, zv),
//};
GlobalPosition = Game.instance.player.GlobalPosition.Clamp(currentRoom.GlobalPosition + Game.roomSize / 2, currentRoom.GlobalPosition + currentRoom.PixelSize - Game.roomSize / 2);
}
public void TransitionToRoom(Room room) {
currentRoom?.Stop();
Game.instance.player.ProcessMode = ProcessModeEnum.Disabled;
var tween = GetTree().CreateTween().SetTrans(Tween.TransitionType.Quad);
tween.SetParallel();
tween.SetEase(Tween.EaseType.InOut);
var pos = GetScreenCenterPosition();
tween.TweenProperty(room, "modulate", Colors.White, 0.5);
tween.TweenProperty(currentRoom, "modulate", new Color(0f, 0f, 0f, 0f), 0.5);
var finish = tween.Chain();
finish.TweenCallback(Callable.From(() => room.Start()));
finish.TweenCallback(Callable.From(delegate {Game.instance.player.ProcessMode = ProcessModeEnum.Inherit;}));
currentRoom = room;
}
}