Notifier
Useful to delete nodes no longer visible onscreen, etc.
- Create an
VisibleOnScreenNotifier
- Attach that node to the object you want to control (bullets for example)
- Adjust the bounding box of the notifier to fit the object
- It will only fire the signal when the whole bounding box has left the screen
- Connect the
screen_exited()
signal from the notifier to a method in your object - Typically this method will simply contain
QueueFree()
private void OnScreenExited() {
QueueFree();
}
Enabler
Can be used to check if a node is visible in the camera.
Then perhaps trigger some behaviour.
- Create a
VisibleOnScreenEnabler2D
- Attach it to an enemy
- By default it will disable everything it is attached to
- So if it’s attached to the root node, it will disable everything, including animations, no need to customise anything
- You can, of course, connect the
on_screen_entered
andon_screen_exited
signals to code to do any customisation you may want
- To test it, you can attach a script to the enemy where it prints something out in the
Process
method
public override void _Process(double delta) {
GD.Print("I'm alive!")
}
Though this is attached to the process
method, which executes on every frame, it will only print that when the enemy is visible on screen.
Customisation
- Connect the signals in the editor
- You can use these simple print messages to test it
- Add whatever customisation you need here
func _on_Screen_entered():
print("The node has entered the screen!")
func _on_Screen_exited():
print("The node has exited the screen!")