Files
FrisbeeFriendsy/game_arena.gd

28 lines
910 B
GDScript

extends Node2D
var camera_follows :Node2D= null
# Called when the node enters the scene tree for the first time.
func _ready():
camera_follows = $Player
# Limit Camera bounds to the TileMap
var map_rect :Rect2i= $TileMap.get_used_rect()
var map_tile_size = $TileMap.tile_set.tile_size
var map_scale_x :float= $TileMap.scale.x * map_tile_size.x
var map_scale_y :float= $TileMap.scale.y * map_tile_size.y
var left_top = map_rect.position
var right_bottom = map_rect.end
$Camera2D.limit_left = left_top[0] * map_scale_x
$Camera2D.limit_top = left_top[1] * map_scale_y
$Camera2D.limit_right = right_bottom[0] * map_scale_x
$Camera2D.limit_bottom = right_bottom[1] * map_scale_y
func camera_follow():
if camera_follows == null:
return
$Camera2D.position = camera_follows.position
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
camera_follow()