Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Twinxs |
First I tried using this code below. The problem is I want the limit to re-adjust based on the currently filled pixel/tile by my ground tilemap. So basically imagine the empty pixel on the scene as collision for my camera limit. I don’t know it makes sense.
func _ready():
var tilemap_rect = get_parent().get_parent().get_node("YSort").get_node("Ground").get_used_rect()
var tilemap_cell_size = get_parent().get_parent().get_node("YSort").get_node("Ground").cell_size
$Camera2D.limit_left = tilemap_rect.position.x * tilemap_cell_size.x
$Camera2D.limit_right = tilemap_rect.end.x * tilemap_cell_size.x
$Camera2D.limit_top = tilemap_rect.position.y * tilemap_cell_size.y
$Camera2D.limit_bottom = tilemap_rect.end.y * tilemap_cell_size.y
here is a representation of what I wanted to happen. the yellow box is camera limit for the initial state of player, once the player reaches the blue circle the camera limit re-adjusts as the green box. finally once the player reaches the pink circle the camera limit re-adjust to the red box. I hope it makes sense