Created
May 11, 2021 09:51
-
-
Save securas/2400b3fa1a31650a270618d1c8851ae6 to your computer and use it in GitHub Desktop.
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
extends Camera2D | |
const SCREEN_SIZE := Vector2( 320, 180 ) | |
var cur_screen := Vector2( 0, 0 ) | |
func _ready(): | |
set_as_toplevel( true ) | |
global_position = get_parent().global_position | |
_update_screen( cur_screen ) | |
func _physics_process(delta): | |
var parent_screen : Vector2 = ( get_parent().global_position / SCREEN_SIZE ).floor() | |
if not parent_screen.is_equal_approx( cur_screen ): | |
_update_screen( parent_screen ) | |
func _update_screen( new_screen : Vector2 ): | |
cur_screen = new_screen | |
global_position = cur_screen * SCREEN_SIZE + SCREEN_SIZE * 0.5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Translation to C# for Godot 4