Skip to content

Instantly share code, notes, and snippets.

@mrkdji
Created May 25, 2021 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrkdji/22fe2e64ac176b5f21c18dba86601059 to your computer and use it in GitHub Desktop.
Save mrkdji/22fe2e64ac176b5f21c18dba86601059 to your computer and use it in GitHub Desktop.
Relevant camera code
onready var screen_size = get_viewport_rect().size;
onready var screen_offset = screen_size * 0.5;
func adjust_scale(new_scale : Vector2):
scale = new_scale;
scale_inv = Vector2.ONE / scale;
create_camera_tranform();
# this is to force the camera to stay inside the level bounds
update_inner_limits(level);
# if room is not null this will force the camera to stay inside a specified rect
update_inner_limits(room);
pass;
func create_camera_tranform():
var t = Transform2D(rotation, position);
t.x *= scale.x;
t.y *= scale.y;
camera_transform = t;
func _physics_process(delta):
match camera_state:
CameraStates.FOLLOW_TARGET:
update_follow_target(delta);
CameraStates.TWEEN_CUTSCENE:
update_tween_cutscene(delta);
# actually moves camera
camera_transform.origin = -position * scale + screen_offset;
get_viewport().set_canvas_transform(camera_transform);
# in order to draw debug shapes
# update();
pass;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment