Camera margin

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By G2700


i created 2 levels, but the margins for the view of the first level need to be different to the second level. How can i specify the view margins for each level?

thanks for help

:bust_in_silhouette: Reply From: zhyrin

Camera2D has the limit_<direction> and drag_margin_<direction> properties you can set. I assume by view margin you mean that the camera should not move past a specified horizontal/vertical value, if that’s the case that’s achieved with the limit_<direction> properties.

You can make these limits variables of your level, and when the level is loaded you update the limits on the camera node.
Alternatively you can use two Position2D nodes in your level to mark where the opposite corners are and when the level starts you can calculate the limits based on their position and distance.