VisibleNotifier2D by axis (x,y)

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

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()
:bust_in_silhouette: Reply From: eons

You can use Area2D nodes with LineShape2D shape (line is like in math, infinite length).

That Area node can be attached to a moving object and delete anything (area or body) in it’s mask on detection (enter or exit, depending on how you set up the line).

Thanks for your response eons !
But, as I’m a complete newbie on Godot, I’ve no clue on how to use it.
Could you please give or point to an example ?

Victoralm | 2018-09-20 23:32

Well, start with something more simple then.
Attach an area with 4 rectangle shapes around the camera, make it kill any other area on area enter (similar to the dodge the creeps tutorial’s enemies).

The things you want to kill must have an area in the corresponding layer.

Then is just matter of putting the shapes where you want these to work.

eons | 2018-09-21 02:23