class_camera2d.rst 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the Camera2D.xml source instead.
  3. .. The source is found in doc/classes or modules/<name>/doc_classes.
  4. .. _class_Camera2D:
  5. Camera2D
  6. ========
  7. **Inherits:** :ref:`Node2D<class_node2d>` **<** :ref:`CanvasItem<class_canvasitem>` **<** :ref:`Node<class_node>` **<** :ref:`Object<class_object>`
  8. **Category:** Core
  9. Brief Description
  10. -----------------
  11. Camera node for 2D scenes.
  12. Member Functions
  13. ----------------
  14. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  15. | void | :ref:`align<class_Camera2D_align>` **(** **)** |
  16. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  17. | void | :ref:`clear_current<class_Camera2D_clear_current>` **(** **)** |
  18. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  19. | void | :ref:`force_update_scroll<class_Camera2D_force_update_scroll>` **(** **)** |
  20. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  21. | :ref:`int<class_int>` | :ref:`get_anchor_mode<class_Camera2D_get_anchor_mode>` **(** **)** const |
  22. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`Vector2<class_vector2>` | :ref:`get_camera_position<class_Camera2D_get_camera_position>` **(** **)** const |
  24. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`Vector2<class_vector2>` | :ref:`get_camera_screen_center<class_Camera2D_get_camera_screen_center>` **(** **)** const |
  26. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`Node<class_node>` | :ref:`get_custom_viewport<class_Camera2D_get_custom_viewport>` **(** **)** const |
  28. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`float<class_float>` | :ref:`get_drag_margin<class_Camera2D_get_drag_margin>` **(** :ref:`int<class_int>` margin **)** const |
  30. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`float<class_float>` | :ref:`get_follow_smoothing<class_Camera2D_get_follow_smoothing>` **(** **)** const |
  32. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`float<class_float>` | :ref:`get_h_offset<class_Camera2D_get_h_offset>` **(** **)** const |
  34. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`int<class_int>` | :ref:`get_limit<class_Camera2D_get_limit>` **(** :ref:`int<class_int>` margin **)** const |
  36. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`Vector2<class_vector2>` | :ref:`get_offset<class_Camera2D_get_offset>` **(** **)** const |
  38. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`float<class_float>` | :ref:`get_v_offset<class_Camera2D_get_v_offset>` **(** **)** const |
  40. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`Vector2<class_vector2>` | :ref:`get_zoom<class_Camera2D_get_zoom>` **(** **)** const |
  42. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`bool<class_bool>` | :ref:`is_current<class_Camera2D_is_current>` **(** **)** const |
  44. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`bool<class_bool>` | :ref:`is_follow_smoothing_enabled<class_Camera2D_is_follow_smoothing_enabled>` **(** **)** const |
  46. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`bool<class_bool>` | :ref:`is_h_drag_enabled<class_Camera2D_is_h_drag_enabled>` **(** **)** const |
  48. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`bool<class_bool>` | :ref:`is_limit_drawing_enabled<class_Camera2D_is_limit_drawing_enabled>` **(** **)** const |
  50. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`bool<class_bool>` | :ref:`is_limit_smoothing_enabled<class_Camera2D_is_limit_smoothing_enabled>` **(** **)** const |
  52. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`bool<class_bool>` | :ref:`is_margin_drawing_enabled<class_Camera2D_is_margin_drawing_enabled>` **(** **)** const |
  54. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`bool<class_bool>` | :ref:`is_rotating<class_Camera2D_is_rotating>` **(** **)** const |
  56. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`bool<class_bool>` | :ref:`is_screen_drawing_enabled<class_Camera2D_is_screen_drawing_enabled>` **(** **)** const |
  58. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`bool<class_bool>` | :ref:`is_v_drag_enabled<class_Camera2D_is_v_drag_enabled>` **(** **)** const |
  60. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  61. | void | :ref:`make_current<class_Camera2D_make_current>` **(** **)** |
  62. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  63. | void | :ref:`reset_smoothing<class_Camera2D_reset_smoothing>` **(** **)** |
  64. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  65. | void | :ref:`set_anchor_mode<class_Camera2D_set_anchor_mode>` **(** :ref:`int<class_int>` anchor_mode **)** |
  66. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  67. | void | :ref:`set_custom_viewport<class_Camera2D_set_custom_viewport>` **(** :ref:`Node<class_node>` viewport **)** |
  68. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  69. | void | :ref:`set_drag_margin<class_Camera2D_set_drag_margin>` **(** :ref:`int<class_int>` margin, :ref:`float<class_float>` drag_margin **)** |
  70. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  71. | void | :ref:`set_enable_follow_smoothing<class_Camera2D_set_enable_follow_smoothing>` **(** :ref:`bool<class_bool>` follow_smoothing **)** |
  72. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  73. | void | :ref:`set_follow_smoothing<class_Camera2D_set_follow_smoothing>` **(** :ref:`float<class_float>` follow_smoothing **)** |
  74. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  75. | void | :ref:`set_h_drag_enabled<class_Camera2D_set_h_drag_enabled>` **(** :ref:`bool<class_bool>` enabled **)** |
  76. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  77. | void | :ref:`set_h_offset<class_Camera2D_set_h_offset>` **(** :ref:`float<class_float>` ofs **)** |
  78. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  79. | void | :ref:`set_limit<class_Camera2D_set_limit>` **(** :ref:`int<class_int>` margin, :ref:`int<class_int>` limit **)** |
  80. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  81. | void | :ref:`set_limit_drawing_enabled<class_Camera2D_set_limit_drawing_enabled>` **(** :ref:`bool<class_bool>` limit_drawing_enabled **)** |
  82. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  83. | void | :ref:`set_limit_smoothing_enabled<class_Camera2D_set_limit_smoothing_enabled>` **(** :ref:`bool<class_bool>` limit_smoothing_enabled **)** |
  84. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  85. | void | :ref:`set_margin_drawing_enabled<class_Camera2D_set_margin_drawing_enabled>` **(** :ref:`bool<class_bool>` margin_drawing_enabled **)** |
  86. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  87. | void | :ref:`set_offset<class_Camera2D_set_offset>` **(** :ref:`Vector2<class_vector2>` offset **)** |
  88. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  89. | void | :ref:`set_rotating<class_Camera2D_set_rotating>` **(** :ref:`bool<class_bool>` rotating **)** |
  90. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  91. | void | :ref:`set_screen_drawing_enabled<class_Camera2D_set_screen_drawing_enabled>` **(** :ref:`bool<class_bool>` screen_drawing_enabled **)** |
  92. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  93. | void | :ref:`set_v_drag_enabled<class_Camera2D_set_v_drag_enabled>` **(** :ref:`bool<class_bool>` enabled **)** |
  94. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  95. | void | :ref:`set_v_offset<class_Camera2D_set_v_offset>` **(** :ref:`float<class_float>` ofs **)** |
  96. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  97. | void | :ref:`set_zoom<class_Camera2D_set_zoom>` **(** :ref:`Vector2<class_vector2>` zoom **)** |
  98. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  99. Member Variables
  100. ----------------
  101. - :ref:`int<class_int>` **anchor_mode** - The Camera2D's anchor point. See [code]ANCHOR_MODE_*[/code] constants.
  102. - :ref:`bool<class_bool>` **current** - If [code]true[/code] this camera is the active camera for the current scene. Only one camera can be current, so setting a different camera [code]current[/code] will disable this one.
  103. - :ref:`float<class_float>` **drag_margin_bottom** - Bottom margin needed to drag the camera. A value of [code]1[/code] makes the camera move only when reaching the edge of the screen.
  104. - :ref:`bool<class_bool>` **drag_margin_h_enabled**
  105. - :ref:`float<class_float>` **drag_margin_left** - Left margin needed to drag the camera. A value of [code]1[/code] makes the camera move only when reaching the edge of the screen.
  106. - :ref:`float<class_float>` **drag_margin_right** - Right margin needed to drag the camera. A value of [code]1[/code] makes the camera move only when reaching the edge of the screen.
  107. - :ref:`float<class_float>` **drag_margin_top** - Top margin needed to drag the camera. A value of [code]1[/code] makes the camera move only when reaching the edge of the screen.
  108. - :ref:`bool<class_bool>` **drag_margin_v_enabled**
  109. - :ref:`bool<class_bool>` **editor_draw_drag_margin**
  110. - :ref:`bool<class_bool>` **editor_draw_limits**
  111. - :ref:`bool<class_bool>` **editor_draw_screen**
  112. - :ref:`int<class_int>` **limit_bottom** - Bottom scroll limit in pixels. The camera stops moving when reaching this value.
  113. - :ref:`int<class_int>` **limit_left** - Left scroll limit in pixels. The camera stops moving when reaching this value.
  114. - :ref:`int<class_int>` **limit_right** - Right scroll limit in pixels. The camera stops moving when reaching this value.
  115. - :ref:`bool<class_bool>` **limit_smoothed**
  116. - :ref:`int<class_int>` **limit_top** - Top scroll limit in pixels. The camera stops moving when reaching this value.
  117. - :ref:`Vector2<class_vector2>` **offset** - The camera's offset, useful for looking around or camera shake animations.
  118. - :ref:`bool<class_bool>` **rotating**
  119. - :ref:`bool<class_bool>` **smoothing_enabled**
  120. - :ref:`float<class_float>` **smoothing_speed**
  121. - :ref:`Vector2<class_vector2>` **zoom** - The camera's zoom relative to the viewport. Values larger than [code]Vector2(1, 1)[/code] zoom out and smaller values zoom in. For an example, use [code]Vector2(0.5, 0.5)[/code] for a 2x zoom in, and [code]Vector2(4, 4)[/code] for a 4x zoom out.
  122. Numeric Constants
  123. -----------------
  124. - **ANCHOR_MODE_DRAG_CENTER** = **1**
  125. - **ANCHOR_MODE_FIXED_TOP_LEFT** = **0**
  126. Description
  127. -----------
  128. Camera node for 2D scenes. It forces the screen (current layer) to scroll following this node. This makes it easier (and faster) to program scrollable scenes than manually changing the position of :ref:`CanvasItem<class_canvasitem>` based nodes.
  129. This node is intended to be a simple helper to get things going quickly and it may happen often that more functionality is desired to change how the camera works. To make your own custom camera node, simply inherit from :ref:`Node2D<class_node2d>` and change the transform of the canvas by calling get_viewport().set_canvas_transform(m) in :ref:`Viewport<class_viewport>`.
  130. Member Function Description
  131. ---------------------------
  132. .. _class_Camera2D_align:
  133. - void **align** **(** **)**
  134. Align the camera to the tracked node
  135. .. _class_Camera2D_clear_current:
  136. - void **clear_current** **(** **)**
  137. .. _class_Camera2D_force_update_scroll:
  138. - void **force_update_scroll** **(** **)**
  139. Force the camera to update scroll immediately.
  140. .. _class_Camera2D_get_anchor_mode:
  141. - :ref:`int<class_int>` **get_anchor_mode** **(** **)** const
  142. .. _class_Camera2D_get_camera_position:
  143. - :ref:`Vector2<class_vector2>` **get_camera_position** **(** **)** const
  144. Return the camera position.
  145. .. _class_Camera2D_get_camera_screen_center:
  146. - :ref:`Vector2<class_vector2>` **get_camera_screen_center** **(** **)** const
  147. .. _class_Camera2D_get_custom_viewport:
  148. - :ref:`Node<class_node>` **get_custom_viewport** **(** **)** const
  149. .. _class_Camera2D_get_drag_margin:
  150. - :ref:`float<class_float>` **get_drag_margin** **(** :ref:`int<class_int>` margin **)** const
  151. Return the margins needed to drag the camera (see :ref:`set_drag_margin<class_Camera2D_set_drag_margin>`).
  152. .. _class_Camera2D_get_follow_smoothing:
  153. - :ref:`float<class_float>` **get_follow_smoothing** **(** **)** const
  154. .. _class_Camera2D_get_h_offset:
  155. - :ref:`float<class_float>` **get_h_offset** **(** **)** const
  156. .. _class_Camera2D_get_limit:
  157. - :ref:`int<class_int>` **get_limit** **(** :ref:`int<class_int>` margin **)** const
  158. Return the scrolling limit in pixels.
  159. .. _class_Camera2D_get_offset:
  160. - :ref:`Vector2<class_vector2>` **get_offset** **(** **)** const
  161. Return the scroll offset.
  162. .. _class_Camera2D_get_v_offset:
  163. - :ref:`float<class_float>` **get_v_offset** **(** **)** const
  164. .. _class_Camera2D_get_zoom:
  165. - :ref:`Vector2<class_vector2>` **get_zoom** **(** **)** const
  166. .. _class_Camera2D_is_current:
  167. - :ref:`bool<class_bool>` **is_current** **(** **)** const
  168. Return true of this is the current camera (see :ref:`make_current<class_Camera2D_make_current>`).
  169. .. _class_Camera2D_is_follow_smoothing_enabled:
  170. - :ref:`bool<class_bool>` **is_follow_smoothing_enabled** **(** **)** const
  171. .. _class_Camera2D_is_h_drag_enabled:
  172. - :ref:`bool<class_bool>` **is_h_drag_enabled** **(** **)** const
  173. .. _class_Camera2D_is_limit_drawing_enabled:
  174. - :ref:`bool<class_bool>` **is_limit_drawing_enabled** **(** **)** const
  175. .. _class_Camera2D_is_limit_smoothing_enabled:
  176. - :ref:`bool<class_bool>` **is_limit_smoothing_enabled** **(** **)** const
  177. .. _class_Camera2D_is_margin_drawing_enabled:
  178. - :ref:`bool<class_bool>` **is_margin_drawing_enabled** **(** **)** const
  179. .. _class_Camera2D_is_rotating:
  180. - :ref:`bool<class_bool>` **is_rotating** **(** **)** const
  181. .. _class_Camera2D_is_screen_drawing_enabled:
  182. - :ref:`bool<class_bool>` **is_screen_drawing_enabled** **(** **)** const
  183. .. _class_Camera2D_is_v_drag_enabled:
  184. - :ref:`bool<class_bool>` **is_v_drag_enabled** **(** **)** const
  185. .. _class_Camera2D_make_current:
  186. - void **make_current** **(** **)**
  187. Make this the current 2D camera for the scene (viewport and layer), in case there's many cameras in the scene.
  188. .. _class_Camera2D_reset_smoothing:
  189. - void **reset_smoothing** **(** **)**
  190. Set the camera's position immediately to its current smoothing destination.
  191. This has no effect if smoothing is disabled.
  192. .. _class_Camera2D_set_anchor_mode:
  193. - void **set_anchor_mode** **(** :ref:`int<class_int>` anchor_mode **)**
  194. .. _class_Camera2D_set_custom_viewport:
  195. - void **set_custom_viewport** **(** :ref:`Node<class_node>` viewport **)**
  196. .. _class_Camera2D_set_drag_margin:
  197. - void **set_drag_margin** **(** :ref:`int<class_int>` margin, :ref:`float<class_float>` drag_margin **)**
  198. Set the margins needed to drag the camera (relative to the screen size). Margin uses the MARGIN\_\* enum. Drag margins of 0,0,0,0 will keep the camera at the center of the screen, while drag margins of 1,1,1,1 will only move when the camera is at the edges.
  199. .. _class_Camera2D_set_enable_follow_smoothing:
  200. - void **set_enable_follow_smoothing** **(** :ref:`bool<class_bool>` follow_smoothing **)**
  201. .. _class_Camera2D_set_follow_smoothing:
  202. - void **set_follow_smoothing** **(** :ref:`float<class_float>` follow_smoothing **)**
  203. .. _class_Camera2D_set_h_drag_enabled:
  204. - void **set_h_drag_enabled** **(** :ref:`bool<class_bool>` enabled **)**
  205. .. _class_Camera2D_set_h_offset:
  206. - void **set_h_offset** **(** :ref:`float<class_float>` ofs **)**
  207. .. _class_Camera2D_set_limit:
  208. - void **set_limit** **(** :ref:`int<class_int>` margin, :ref:`int<class_int>` limit **)**
  209. Set the scrolling limit in pixels.
  210. .. _class_Camera2D_set_limit_drawing_enabled:
  211. - void **set_limit_drawing_enabled** **(** :ref:`bool<class_bool>` limit_drawing_enabled **)**
  212. .. _class_Camera2D_set_limit_smoothing_enabled:
  213. - void **set_limit_smoothing_enabled** **(** :ref:`bool<class_bool>` limit_smoothing_enabled **)**
  214. Smooth camera when reaching camera limits.
  215. This requires camera smoothing being enabled to have a noticeable effect.
  216. .. _class_Camera2D_set_margin_drawing_enabled:
  217. - void **set_margin_drawing_enabled** **(** :ref:`bool<class_bool>` margin_drawing_enabled **)**
  218. .. _class_Camera2D_set_offset:
  219. - void **set_offset** **(** :ref:`Vector2<class_vector2>` offset **)**
  220. Set the scroll offset. Useful for looking around or camera shake animations.
  221. .. _class_Camera2D_set_rotating:
  222. - void **set_rotating** **(** :ref:`bool<class_bool>` rotating **)**
  223. .. _class_Camera2D_set_screen_drawing_enabled:
  224. - void **set_screen_drawing_enabled** **(** :ref:`bool<class_bool>` screen_drawing_enabled **)**
  225. .. _class_Camera2D_set_v_drag_enabled:
  226. - void **set_v_drag_enabled** **(** :ref:`bool<class_bool>` enabled **)**
  227. .. _class_Camera2D_set_v_offset:
  228. - void **set_v_offset** **(** :ref:`float<class_float>` ofs **)**
  229. .. _class_Camera2D_set_zoom:
  230. - void **set_zoom** **(** :ref:`Vector2<class_vector2>` zoom **)**