How do I get the length of a scene?

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

I am trying to make a level transition script similar to metroid. It creates a scene, runs the transition, and then deletes the old scene. This is the code so far:

enum DIRECTION { Up, Down, Left, Right }
export(DIRECTION) var direc
export(PackedScene) var scene_to

func _on_Area2D_body_entered(body):
	if body.is_in_group("player"):
		var player = body
		# Create scene
		var newScene = scene_to.instance()
            # PROBLEM! Move scene to a position relative to existing scene


		# Remove player from old scene
		owner.remove_child(player)
		# Add player to new scene
		
		# Move player into scene
		
		# Destroy this scene. Goodbye self!

My goal is to make it so the editor only has to say the direction the new scene will be placed in, and the new scene will be spawned there. If I wanted to make a door in the LEFT direction, I’ll have to move the new scene to oldscene.position.x minus the size (width) of my new scene. How do I do that?

My scenes rely heavily on tilesets, and are made to not use death-traps. This means entire scenes are bounded completely by the main tileset. I believe I could finagle a solution through that.

:bust_in_silhouette: Reply From: Kanor

So, for lack of a solution, I decided to make the root of a scene contain the bounds of the map in question, and call that whenever I need the scene’s size:

tool
extends Node2D

export(int) var left = 32
export(int) var right = 32
export(int) var up = 32
export(int) var down = 32

var prev_left = 0
var prev_right = 0
var prev_up = 0
var prev_down = 0

func _process(delta):
	if prev_left != left or prev_right != right \
		or prev_up != up or prev_down != down:
		update()

# Called when the node enters the scene tree for the first time.
func _draw():
	if not Engine.editor_hint:
		return
	
	draw_line(Vector2(left, up-320), Vector2(left, down+320), Color(1, 0, 0), 5)
	draw_line(Vector2(right, up-320), Vector2(right, down+320), Color(1, 0, 0), 5)
	draw_line(Vector2(left-320, up), Vector2(right+320, up), Color(1, 0, 0), 5)
	draw_line(Vector2(left-320, down), Vector2(right+320, down), Color(1, 0, 0), 5)

The tool part allows the editor to draw lines on the borders without it appearing in-game. Plus, I can use this for setting camera limits after changing rooms. I’m going with this solution for now.