0 votes

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


onready var sprite = $Sprite

var spring_path = "res://scenes/Spring.tscn"

var sprite_half_width

var screenSize

func _ready():
    screenSize = OS.get_window_size()
    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()
        new_spring.position = Vector2(0, -new_spring.height)

func _on_body_entered(body):
    if body.name == "Player":
        if body.position.y < position.y:
    elif body.name == "GrassPlatform" or body.name == "GrassPlatformSmall":
        position.y += 60

func _on_VisibilityNotifier2D_screen_exited():
in Engine by (43 points)

1 Answer

0 votes

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).

by (7,946 points)

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 ?

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.