On Screen Visibility

Notifier

Useful to delete nodes no longer visible onscreen, etc.

  1. Create an VisibleOnScreenNotifier
  2. Attach that node to the object you want to control (bullets for example)
  3. Adjust the bounding box of the notifier to fit the object
    1. It will only fire the signal when the whole bounding box has left the screen
  4. Connect the screen_exited() signal from the notifier to a method in your object
  5. 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.

  1. Create a VisibleOnScreenEnabler2D
  2. Attach it to an enemy
  3. By default it will disable everything it is attached to
  4. So if it’s attached to the root node, it will disable everything, including animations, no need to customise anything
  5. You can, of course, connect the on_screen_entered and on_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

  1. Connect the signals in the editor
  2. You can use these simple print messages to test it
  3. 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!")