Skip to content

2D Project

Useful classes

VisibleOnScreenNotifier2D
signal screen_exited()

Useful to delete objects out of screen.

# node tree
Area2D
-> VisibleOnScreenNotifier2D 

# connect screen_exited to Area2D and impl:
func _on_visible_on_screen_notifier_2d_screen_exited():
    queue_free()

Different Resolutions

The base size can be set in Project Settings --> Display --> Window --> Size

For high-resolution non-pixel desktop games, we can start from base size of 3840 x 2160 (4K).

If you are developing with a smaller monitor, change Window Width/Height Override (need to check advanced settings) to a smaller size (like 1920x1080), so the debugging window won't go beyond your monitor.

Then we need to allow resize (keep aspect ratio) the window by setting:

  • Stretch mode = canvas_items
  • Stretch aspect = expand

Now your window start from 1920x1280 but renders high quality images and automatically downscale them!

Correctly get window size:

var window = get_window()
# actual size of current window
print(window.size) # e.g., 1920x1080
# size before scaling
print(window.content_scale_size) # 3820x2160

Steps for a new project

  • Configure viewport resolution in Project settings --> Display --> Window --> Size .
  • Configure main scene in Project settings --> Application --> Run.