I'm trying a platform jump tutorial and, while seaching a way to free a node from memory when it's out of the screen, I found out about VisibleNotifier2D. Then, for nodes that's has fixed positions, I'm good. But for Path2D nodes, I'm having some troubles...
The question is:
Is there a way to free a node from memory (queue_free()) only whe it's not visible on the y coordenate, but keep it even if it's get invisible on the x coordenate ?
My actual code is like this:
extends Area2D
const SPRING_CHANCE = 5
onready var sprite = $Sprite
var spring_path = "res://scenes/Spring.tscn"
var sprite_half_width
var screenSize
func _ready():
screenSize = OS.get_window_size()
randomize()
connect("body_entered", self, "_on_body_entered")
sprite_half_width = sprite.texture.get_width() / 2 * scale.x
if rand_range(0, 100) > 100 - SPRING_CHANCE:
var new_spring = load(spring_path).instance()
add_child(new_spring)
new_spring.position = Vector2(0, -new_spring.height)
func _on_body_entered(body):
if body.name == "Player":
if body.position.y < position.y:
body.jump()
elif body.name == "GrassPlatform" or body.name == "GrassPlatformSmall":
position.y += 60
func _on_VisibilityNotifier2D_screen_exited():
queue_free()