multiple_resolutions.rst 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. .. _doc_multiple_resolutions:
  2. Multiple resolutions
  3. ====================
  4. Base resolution
  5. ---------------
  6. A base screen resolution for the project can be specified in the project
  7. settings under ``display``, ``window``
  8. .. image:: img/screenres.png
  9. However, what it does is not completely obvious. When running on PC, the
  10. engine will attempt to set this resolution (or use something smaller if
  11. it fails). On mobile, consoles or devices with a fixed resolution or
  12. full screen rendering, this resolution will be ignored and the native
  13. resolution will be used instead. To compensate for this, Godot offers
  14. many ways to control how the screen will resize and stretch to different
  15. screen sizes.
  16. Resizing
  17. --------
  18. There are several types of devices, with several types of screens, which
  19. in turn have different pixel density and resolutions. Handling all of
  20. them can be a lot of work, so Godot tries to make the developer's life a
  21. little easier. The :ref:`Viewport <class_Viewport>`
  22. node has several functions to handle resizing, and the root node of the
  23. scene tree is always a viewport (scenes loaded are instanced as a child
  24. of it, and it can always be accessed by calling
  25. ``get_tree().get_root()`` or ``get_node("/root")``).
  26. In any case, while changing the root Viewport params is probably the
  27. most flexible way to deal with the problem, it can be a lot of work,
  28. code and guessing, so Godot provides a simple set of parameters in the
  29. project settings to handle multiple resolutions.
  30. Stretch settings
  31. ----------------
  32. Stretch settings are located in the project settings, it's just a bunch
  33. of configuration variables that provide several options:
  34. .. image:: img/stretchsettings.png
  35. Stretch mode
  36. ------------
  37. - **Disabled**: The first is the stretch mode. By default this is
  38. disabled, which means no stretching happens (the bigger the screen or
  39. window, the bigger the resolution, always matching pixels 1:1).
  40. - **2D**: In this mode, the resolution specified in display/width and
  41. display/height in the project settings will be stretched to cover the
  42. whole screen. This means that 3D will be unaffected (will just render
  43. to higher-res) and 2D will also be rendered at higher-res, just
  44. enlarged.
  45. - **Viewport**: Viewport scaling is different, the root
  46. :ref:`Viewport <class_Viewport>`
  47. is set as a render target, and still renders precisely to the
  48. resolution specified in the ``display/`` section of the project
  49. settings. Finally, this viewport is copied and scaled to fit the
  50. screen. This mode is useful when working with pixel-precise games,
  51. or for the sake of rendering to a lower resolution for improving
  52. performance.
  53. .. image:: img/stretch.png
  54. Stretch aspect
  55. --------------
  56. - **Ignore**: Ignore the aspect ratio when stretching the screen. This
  57. means that the original resolution will be stretched to fit the new
  58. one, even if it's wider or narrower.
  59. - **Keep**: Keep aspect ratio when stretching the screen. This means
  60. that the original resolution will be kept when fitting the new one,
  61. and black bars will be added to the sides or the top/bottom of the
  62. screen.
  63. - **Keep Width**: Keep aspect ratio when stretching the screen, but if
  64. the resulting screen is taller than the specified resolution, it will
  65. be stretched vertically (and more vertical resolution will be
  66. reported in the viewport, proportionally). This is usually the best
  67. option for creating GUIs or HUDs that scale, so some controls can be
  68. anchored to the bottom (:ref:`doc_size_and_anchors`).
  69. - **Keep Height**: Keep aspect ratio when stretching the screen, but if
  70. the resulting screen is wider than the specified resolution, it will
  71. be stretched horizontally (and more horizontal resolution will be
  72. reported in the viewport, proportionally). This is usually the best
  73. option for 2D games that scroll horizontally (like runners or
  74. platformers).
  75. - **Expand**: Keep aspect ratio when stretching the screen, but keep
  76. neither width nor height. Depending on the screen aspect ratio, the
  77. viewport will either report more horizontal resolution (if the screen
  78. is wider than the original resolution) or more vertical resolution
  79. (if the screen is taller than the original resolution).