Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | PIZZA_ALERT |
I have a Camera2D scene that operates my camera size and travel limits for different scenes. Within this scene is a simple child node called “Limits” (just acts like a folder) and inside this are two Position2D children called “TopLeftLimit” and “BottomRightLimit.” These limits control the outer reaches of where the camera can travel in any given scene, and show as crosshairs in the editor but not in-game (I believe this is always the case for Position2D’s but may be wrong). This is great to work with as all you have to do is move two crosshairs with your mouse in the editor to desired locations and boom, the camera is bound to stay between them.
Editor Screenshot: Camera2D - Album on Imgur
However, I may have some times that I don’t want a limit on my camera’s outer bounds, say, maybe during development/debugging, and I would like to be able to turn these limits off, physically in-game (removing camera travel limits) as well as visually in the editor (hiding the crosshairs). I successfully did this for the physical, in-game portion with an export boolean checkbox called “Camera Limits Active” which sets the Limits child node (and therefore its children, the TopLeft and BottomRight limits) to be removed if said checkbox is unchecked (false), but for the life of me, I can’t get these stupid crosshairs to hide unless I manually go into the editor and click the little eyeballs next to them or uncheck the “visible” checkbox on both of them in the Inspector. I want my one custom export variable checkbox to do this automatically so that there is a visual indication within the editor that my camera limits are off, thru code.
What am I doing wrong? Is this possible?
The following code is attached to the Camera2D scene on the parent, Camera2D node.
# Extensions
extends Camera2D
# Constants
export(bool) var cameraLimitsActive = true
# Variables
onready var limits = $Limits
onready var topLeftLimit = $Limits/TopLeftLimit
onready var bottomRightLimit = $Limits/BottomRightLimit
# Functions
func _ready():
if cameraLimitsActive:
topLeftLimit.visible = true
bottomRightLimit.visible = true
limit_top = topLeftLimit.position.y
limit_left = topLeftLimit.position.x
limit_bottom = bottomRightLimit.position.y
limit_right = bottomRightLimit.position.x
else:
remove_child(limits)
topLeftLimit.visible = false
bottomRightLimit.visible = false