-
-
Save mrkdji/22fe2e64ac176b5f21c18dba86601059 to your computer and use it in GitHub Desktop.
Relevant camera code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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