How define if object is in view

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

I’m making a custom TileMap and I need to define if a cell is in view to mark it for drawing.

:bust_in_silhouette: Reply From: 1izNoob

Not sure what you mean, but there is a node called VisibilityNotifier that you can use for that. It can both check the entire viewport and a camera, quite a useful little node.

What should I do if I don’t create CanvasItem, but I use DrawRect()?

BorisJohnson | 2020-01-31 11:23

:bust_in_silhouette: Reply From: BorisJohnson

My solution. I didn’t find the built-in method.

func _intersects_viewport(rect: Rect2) -> bool:
    var transform : Transform2D = get_canvas_transform()
    var scale : Vector2 = transform.get_scale()
    return Rect2(-transform.origin / scale, get_viewport_rect().size / scale).intersects(rect)