-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameCamera.cs
More file actions
43 lines (38 loc) · 1.17 KB
/
GameCamera.cs
File metadata and controls
43 lines (38 loc) · 1.17 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
namespace CreatureBattler;
/// <summary>
/// The GameCamera that renders to a render texture.
/// </summary>
public class GameCamera
{
public RenderTexture2D RenderTexture;
private Camera2D _interalCamera;
public GameCamera()
{
RenderTexture = LoadRenderTexture((int)Game.GameSize.X, (int)Game.GameSize.Y);
FixRenderTexture();
_interalCamera = new Camera2D
{
Offset = new Vector2((int)(Game.GameSize.X / 2), (int)(Game.GameSize.Y / 2)),
Rotation = 0,
Target = new Vector2((int)(Game.GameSize.X / 2), (int)(Game.GameSize.Y / 2)),
Zoom = 1
};
}
public void FixRenderTexture()
{
SetTextureFilter(RenderTexture.Texture, Point);
GenTextureMipmaps(ref RenderTexture.Texture);
}
/// <summary>
/// Centers the camera at a position.
/// </summary>
/// <param name="position">A vector2 of the position to target</param>
public void UpdatePosition(Vector2 position)
{
_interalCamera.Target = position / 2;
}
public static implicit operator Camera2D(GameCamera camera)
{
return camera._interalCamera;
}
}