forked from mvrry/12Goat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrid-snapping camera
More file actions
32 lines (25 loc) · 787 Bytes
/
Grid-snapping camera
File metadata and controls
32 lines (25 loc) · 787 Bytes
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
extends Node2D
var grid_size = Vector2()
var grid_position = Vector2()
onready var parent = get_parent()
func _ready():
$Camera2D.position = Vector2()
grid_size = OS.get_screen_size()
set_as_toplevel(true)
update_grid_position()
func _physics_process(delta):
update_grid_position()
func update_grid_position():
var x = round(parent.position.x / grid_size.x)
var y = round(parent.position.y / grid_size.y)
var new_grid_position = Vector2(x, y)
if grid_position == new_grid_position:
return
grid_position = new_grid_position
jump_to_grid_position()
func calculate_grid_position():
var x = round(parent.position.x / grid_size.x)
var y = round(parent.position.y / grid_size.y)
return Vector2(x, y)
func jump_to_grid_position():
position = (grid_position * grid_size)