VisibilityNotifier2D

Inherits: Node2D < CanvasItem < Node < Object

Inherited By: VisibilityEnabler2D

Detects approximately when the node is visible on screen.

Description

The VisibilityNotifier2D detects when it is visible on the screen. It also notifies when its bounding rectangle enters or exits the screen or a viewport.

If you want nodes to be disabled automatically when they exit the screen, use VisibilityEnabler2D instead.

Note: For performance reasons, VisibilityNotifier2D uses an approximate heuristic with precision determined by ProjectSettings.world/2d/cell_size. If you need precise visibility checking, use another method such as adding an Area2D node as a child of a Camera2D node.

Tutorials

Properties

Rect2

rect

Rect2( -10, -10, 20, 20 )

Methods

bool

is_on_screen ( ) const


Signals

screen_entered ( )

Emitted when the VisibilityNotifier2D enters the screen.


screen_exited ( )

Emitted when the VisibilityNotifier2D exits the screen.


viewport_entered ( Viewport viewport )

Emitted when the VisibilityNotifier2D enters a Viewport's view.


viewport_exited ( Viewport viewport )

Emitted when the VisibilityNotifier2D exits a Viewport's view.


Property Descriptions

Rect2 rect = Rect2( -10, -10, 20, 20 )

  • void set_rect ( Rect2 value )

  • Rect2 get_rect ( )

The VisibilityNotifier2D's bounding rectangle.


Method Descriptions

bool is_on_screen ( ) const

If true, the bounding rectangle is on the screen.

Note: It takes one frame for the node's visibility to be assessed once added to the scene tree, so this method will return false right after it is instantiated, even if it will be on screen in the draw pass.