class_camera2d.rst 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the Camera2D.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_Camera2D:
  6. Camera2D
  7. ========
  8. **Inherits:** :ref:`Node2D<class_Node2D>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  9. **Category:** Core
  10. Brief Description
  11. -----------------
  12. Camera node for 2D scenes.
  13. Properties
  14. ----------
  15. +---------------------------------------------------------------+---------------------------------------------------------------------------------+
  16. | :ref:`AnchorMode<enum_Camera2D_AnchorMode>` | :ref:`anchor_mode<class_Camera2D_property_anchor_mode>` |
  17. +---------------------------------------------------------------+---------------------------------------------------------------------------------+
  18. | :ref:`bool<class_bool>` | :ref:`current<class_Camera2D_property_current>` |
  19. +---------------------------------------------------------------+---------------------------------------------------------------------------------+
  20. | :ref:`Node<class_Node>` | :ref:`custom_viewport<class_Camera2D_property_custom_viewport>` |
  21. +---------------------------------------------------------------+---------------------------------------------------------------------------------+
  22. | :ref:`float<class_float>` | :ref:`drag_margin_bottom<class_Camera2D_property_drag_margin_bottom>` |
  23. +---------------------------------------------------------------+---------------------------------------------------------------------------------+
  24. | :ref:`bool<class_bool>` | :ref:`drag_margin_h_enabled<class_Camera2D_property_drag_margin_h_enabled>` |
  25. +---------------------------------------------------------------+---------------------------------------------------------------------------------+
  26. | :ref:`float<class_float>` | :ref:`drag_margin_left<class_Camera2D_property_drag_margin_left>` |
  27. +---------------------------------------------------------------+---------------------------------------------------------------------------------+
  28. | :ref:`float<class_float>` | :ref:`drag_margin_right<class_Camera2D_property_drag_margin_right>` |
  29. +---------------------------------------------------------------+---------------------------------------------------------------------------------+
  30. | :ref:`float<class_float>` | :ref:`drag_margin_top<class_Camera2D_property_drag_margin_top>` |
  31. +---------------------------------------------------------------+---------------------------------------------------------------------------------+
  32. | :ref:`bool<class_bool>` | :ref:`drag_margin_v_enabled<class_Camera2D_property_drag_margin_v_enabled>` |
  33. +---------------------------------------------------------------+---------------------------------------------------------------------------------+
  34. | :ref:`bool<class_bool>` | :ref:`editor_draw_drag_margin<class_Camera2D_property_editor_draw_drag_margin>` |
  35. +---------------------------------------------------------------+---------------------------------------------------------------------------------+
  36. | :ref:`bool<class_bool>` | :ref:`editor_draw_limits<class_Camera2D_property_editor_draw_limits>` |
  37. +---------------------------------------------------------------+---------------------------------------------------------------------------------+
  38. | :ref:`bool<class_bool>` | :ref:`editor_draw_screen<class_Camera2D_property_editor_draw_screen>` |
  39. +---------------------------------------------------------------+---------------------------------------------------------------------------------+
  40. | :ref:`int<class_int>` | :ref:`limit_bottom<class_Camera2D_property_limit_bottom>` |
  41. +---------------------------------------------------------------+---------------------------------------------------------------------------------+
  42. | :ref:`int<class_int>` | :ref:`limit_left<class_Camera2D_property_limit_left>` |
  43. +---------------------------------------------------------------+---------------------------------------------------------------------------------+
  44. | :ref:`int<class_int>` | :ref:`limit_right<class_Camera2D_property_limit_right>` |
  45. +---------------------------------------------------------------+---------------------------------------------------------------------------------+
  46. | :ref:`bool<class_bool>` | :ref:`limit_smoothed<class_Camera2D_property_limit_smoothed>` |
  47. +---------------------------------------------------------------+---------------------------------------------------------------------------------+
  48. | :ref:`int<class_int>` | :ref:`limit_top<class_Camera2D_property_limit_top>` |
  49. +---------------------------------------------------------------+---------------------------------------------------------------------------------+
  50. | :ref:`Vector2<class_Vector2>` | :ref:`offset<class_Camera2D_property_offset>` |
  51. +---------------------------------------------------------------+---------------------------------------------------------------------------------+
  52. | :ref:`float<class_float>` | :ref:`offset_h<class_Camera2D_property_offset_h>` |
  53. +---------------------------------------------------------------+---------------------------------------------------------------------------------+
  54. | :ref:`float<class_float>` | :ref:`offset_v<class_Camera2D_property_offset_v>` |
  55. +---------------------------------------------------------------+---------------------------------------------------------------------------------+
  56. | :ref:`Camera2DProcessMode<enum_Camera2D_Camera2DProcessMode>` | :ref:`process_mode<class_Camera2D_property_process_mode>` |
  57. +---------------------------------------------------------------+---------------------------------------------------------------------------------+
  58. | :ref:`bool<class_bool>` | :ref:`rotating<class_Camera2D_property_rotating>` |
  59. +---------------------------------------------------------------+---------------------------------------------------------------------------------+
  60. | :ref:`bool<class_bool>` | :ref:`smoothing_enabled<class_Camera2D_property_smoothing_enabled>` |
  61. +---------------------------------------------------------------+---------------------------------------------------------------------------------+
  62. | :ref:`float<class_float>` | :ref:`smoothing_speed<class_Camera2D_property_smoothing_speed>` |
  63. +---------------------------------------------------------------+---------------------------------------------------------------------------------+
  64. | :ref:`Vector2<class_Vector2>` | :ref:`zoom<class_Camera2D_property_zoom>` |
  65. +---------------------------------------------------------------+---------------------------------------------------------------------------------+
  66. Methods
  67. -------
  68. +-------------------------------+---------------------------------------------------------------------------------------------------+
  69. | void | :ref:`align<class_Camera2D_method_align>` **(** **)** |
  70. +-------------------------------+---------------------------------------------------------------------------------------------------+
  71. | void | :ref:`clear_current<class_Camera2D_method_clear_current>` **(** **)** |
  72. +-------------------------------+---------------------------------------------------------------------------------------------------+
  73. | void | :ref:`force_update_scroll<class_Camera2D_method_force_update_scroll>` **(** **)** |
  74. +-------------------------------+---------------------------------------------------------------------------------------------------+
  75. | :ref:`Vector2<class_Vector2>` | :ref:`get_camera_position<class_Camera2D_method_get_camera_position>` **(** **)** const |
  76. +-------------------------------+---------------------------------------------------------------------------------------------------+
  77. | :ref:`Vector2<class_Vector2>` | :ref:`get_camera_screen_center<class_Camera2D_method_get_camera_screen_center>` **(** **)** const |
  78. +-------------------------------+---------------------------------------------------------------------------------------------------+
  79. | void | :ref:`make_current<class_Camera2D_method_make_current>` **(** **)** |
  80. +-------------------------------+---------------------------------------------------------------------------------------------------+
  81. | void | :ref:`reset_smoothing<class_Camera2D_method_reset_smoothing>` **(** **)** |
  82. +-------------------------------+---------------------------------------------------------------------------------------------------+
  83. Enumerations
  84. ------------
  85. .. _enum_Camera2D_AnchorMode:
  86. .. _class_Camera2D_constant_ANCHOR_MODE_FIXED_TOP_LEFT:
  87. .. _class_Camera2D_constant_ANCHOR_MODE_DRAG_CENTER:
  88. enum **AnchorMode**:
  89. - **ANCHOR_MODE_FIXED_TOP_LEFT** = **0** --- The camera's position is fixed so that the top-left corner is always at the origin.
  90. - **ANCHOR_MODE_DRAG_CENTER** = **1** --- The camera's position takes into account vertical/horizontal offsets and the screen size.
  91. ----
  92. .. _enum_Camera2D_Camera2DProcessMode:
  93. .. _class_Camera2D_constant_CAMERA2D_PROCESS_PHYSICS:
  94. .. _class_Camera2D_constant_CAMERA2D_PROCESS_IDLE:
  95. enum **Camera2DProcessMode**:
  96. - **CAMERA2D_PROCESS_PHYSICS** = **0**
  97. - **CAMERA2D_PROCESS_IDLE** = **1**
  98. Description
  99. -----------
  100. 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.
  101. 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>`.
  102. Property Descriptions
  103. ---------------------
  104. .. _class_Camera2D_property_anchor_mode:
  105. - :ref:`AnchorMode<enum_Camera2D_AnchorMode>` **anchor_mode**
  106. +----------+------------------------+
  107. | *Setter* | set_anchor_mode(value) |
  108. +----------+------------------------+
  109. | *Getter* | get_anchor_mode() |
  110. +----------+------------------------+
  111. The Camera2D's anchor point. See ``ANCHOR_MODE_*`` constants.
  112. ----
  113. .. _class_Camera2D_property_current:
  114. - :ref:`bool<class_bool>` **current**
  115. +----------+--------------+
  116. | *Getter* | is_current() |
  117. +----------+--------------+
  118. If ``true``, the camera is the active camera for the current scene. Only one camera can be current, so setting a different camera ``current`` will disable this one.
  119. ----
  120. .. _class_Camera2D_property_custom_viewport:
  121. - :ref:`Node<class_Node>` **custom_viewport**
  122. +----------+----------------------------+
  123. | *Setter* | set_custom_viewport(value) |
  124. +----------+----------------------------+
  125. | *Getter* | get_custom_viewport() |
  126. +----------+----------------------------+
  127. The custom :ref:`Viewport<class_Viewport>` node attached to the ``Camera2D``. If null or not a :ref:`Viewport<class_Viewport>`, uses the default viewport instead.
  128. ----
  129. .. _class_Camera2D_property_drag_margin_bottom:
  130. - :ref:`float<class_float>` **drag_margin_bottom**
  131. +----------+------------------------+
  132. | *Setter* | set_drag_margin(value) |
  133. +----------+------------------------+
  134. | *Getter* | get_drag_margin() |
  135. +----------+------------------------+
  136. Bottom margin needed to drag the camera. A value of ``1`` makes the camera move only when reaching the edge of the screen.
  137. ----
  138. .. _class_Camera2D_property_drag_margin_h_enabled:
  139. - :ref:`bool<class_bool>` **drag_margin_h_enabled**
  140. +----------+---------------------------+
  141. | *Setter* | set_h_drag_enabled(value) |
  142. +----------+---------------------------+
  143. | *Getter* | is_h_drag_enabled() |
  144. +----------+---------------------------+
  145. If ``true``, the camera only moves when reaching the horizontal drag margins. If ``false``, the camera moves horizontally regardless of margins. Default value: ``true``.
  146. ----
  147. .. _class_Camera2D_property_drag_margin_left:
  148. - :ref:`float<class_float>` **drag_margin_left**
  149. +----------+------------------------+
  150. | *Setter* | set_drag_margin(value) |
  151. +----------+------------------------+
  152. | *Getter* | get_drag_margin() |
  153. +----------+------------------------+
  154. Left margin needed to drag the camera. A value of ``1`` makes the camera move only when reaching the edge of the screen.
  155. ----
  156. .. _class_Camera2D_property_drag_margin_right:
  157. - :ref:`float<class_float>` **drag_margin_right**
  158. +----------+------------------------+
  159. | *Setter* | set_drag_margin(value) |
  160. +----------+------------------------+
  161. | *Getter* | get_drag_margin() |
  162. +----------+------------------------+
  163. Right margin needed to drag the camera. A value of ``1`` makes the camera move only when reaching the edge of the screen.
  164. ----
  165. .. _class_Camera2D_property_drag_margin_top:
  166. - :ref:`float<class_float>` **drag_margin_top**
  167. +----------+------------------------+
  168. | *Setter* | set_drag_margin(value) |
  169. +----------+------------------------+
  170. | *Getter* | get_drag_margin() |
  171. +----------+------------------------+
  172. Top margin needed to drag the camera. A value of ``1`` makes the camera move only when reaching the edge of the screen.
  173. ----
  174. .. _class_Camera2D_property_drag_margin_v_enabled:
  175. - :ref:`bool<class_bool>` **drag_margin_v_enabled**
  176. +----------+---------------------------+
  177. | *Setter* | set_v_drag_enabled(value) |
  178. +----------+---------------------------+
  179. | *Getter* | is_v_drag_enabled() |
  180. +----------+---------------------------+
  181. If ``true``, the camera only moves when reaching the vertical drag margins. If ``false``, the camera moves vertically regardless of margins. Default value: ``true``.
  182. ----
  183. .. _class_Camera2D_property_editor_draw_drag_margin:
  184. - :ref:`bool<class_bool>` **editor_draw_drag_margin**
  185. +----------+-----------------------------------+
  186. | *Setter* | set_margin_drawing_enabled(value) |
  187. +----------+-----------------------------------+
  188. | *Getter* | is_margin_drawing_enabled() |
  189. +----------+-----------------------------------+
  190. If ``true``, draws the camera's drag margin rectangle in the editor. Default value: ``false``
  191. ----
  192. .. _class_Camera2D_property_editor_draw_limits:
  193. - :ref:`bool<class_bool>` **editor_draw_limits**
  194. +----------+----------------------------------+
  195. | *Setter* | set_limit_drawing_enabled(value) |
  196. +----------+----------------------------------+
  197. | *Getter* | is_limit_drawing_enabled() |
  198. +----------+----------------------------------+
  199. If ``true``, draws the camera's limits rectangle in the editor. Default value: ``true``
  200. ----
  201. .. _class_Camera2D_property_editor_draw_screen:
  202. - :ref:`bool<class_bool>` **editor_draw_screen**
  203. +----------+-----------------------------------+
  204. | *Setter* | set_screen_drawing_enabled(value) |
  205. +----------+-----------------------------------+
  206. | *Getter* | is_screen_drawing_enabled() |
  207. +----------+-----------------------------------+
  208. If ``true``, draws the camera's screen rectangle in the editor. Default value: ``false``
  209. ----
  210. .. _class_Camera2D_property_limit_bottom:
  211. - :ref:`int<class_int>` **limit_bottom**
  212. +----------+------------------+
  213. | *Setter* | set_limit(value) |
  214. +----------+------------------+
  215. | *Getter* | get_limit() |
  216. +----------+------------------+
  217. Bottom scroll limit in pixels. The camera stops moving when reaching this value.
  218. ----
  219. .. _class_Camera2D_property_limit_left:
  220. - :ref:`int<class_int>` **limit_left**
  221. +----------+------------------+
  222. | *Setter* | set_limit(value) |
  223. +----------+------------------+
  224. | *Getter* | get_limit() |
  225. +----------+------------------+
  226. Left scroll limit in pixels. The camera stops moving when reaching this value.
  227. ----
  228. .. _class_Camera2D_property_limit_right:
  229. - :ref:`int<class_int>` **limit_right**
  230. +----------+------------------+
  231. | *Setter* | set_limit(value) |
  232. +----------+------------------+
  233. | *Getter* | get_limit() |
  234. +----------+------------------+
  235. Right scroll limit in pixels. The camera stops moving when reaching this value.
  236. ----
  237. .. _class_Camera2D_property_limit_smoothed:
  238. - :ref:`bool<class_bool>` **limit_smoothed**
  239. +----------+------------------------------------+
  240. | *Setter* | set_limit_smoothing_enabled(value) |
  241. +----------+------------------------------------+
  242. | *Getter* | is_limit_smoothing_enabled() |
  243. +----------+------------------------------------+
  244. If ``true``, the camera smoothly stops when reaches its limits. Default value: ``false``
  245. ----
  246. .. _class_Camera2D_property_limit_top:
  247. - :ref:`int<class_int>` **limit_top**
  248. +----------+------------------+
  249. | *Setter* | set_limit(value) |
  250. +----------+------------------+
  251. | *Getter* | get_limit() |
  252. +----------+------------------+
  253. Top scroll limit in pixels. The camera stops moving when reaching this value.
  254. ----
  255. .. _class_Camera2D_property_offset:
  256. - :ref:`Vector2<class_Vector2>` **offset**
  257. +----------+-------------------+
  258. | *Setter* | set_offset(value) |
  259. +----------+-------------------+
  260. | *Getter* | get_offset() |
  261. +----------+-------------------+
  262. The camera's offset, useful for looking around or camera shake animations.
  263. ----
  264. .. _class_Camera2D_property_offset_h:
  265. - :ref:`float<class_float>` **offset_h**
  266. +----------+---------------------+
  267. | *Setter* | set_h_offset(value) |
  268. +----------+---------------------+
  269. | *Getter* | get_h_offset() |
  270. +----------+---------------------+
  271. The horizontal offset of the camera, relative to the drag margins. Default value: ``0``
  272. ----
  273. .. _class_Camera2D_property_offset_v:
  274. - :ref:`float<class_float>` **offset_v**
  275. +----------+---------------------+
  276. | *Setter* | set_v_offset(value) |
  277. +----------+---------------------+
  278. | *Getter* | get_v_offset() |
  279. +----------+---------------------+
  280. The vertical offset of the camera, relative to the drag margins. Default value: ``0``
  281. ----
  282. .. _class_Camera2D_property_process_mode:
  283. - :ref:`Camera2DProcessMode<enum_Camera2D_Camera2DProcessMode>` **process_mode**
  284. +----------+-------------------------+
  285. | *Setter* | set_process_mode(value) |
  286. +----------+-------------------------+
  287. | *Getter* | get_process_mode() |
  288. +----------+-------------------------+
  289. ----
  290. .. _class_Camera2D_property_rotating:
  291. - :ref:`bool<class_bool>` **rotating**
  292. +----------+---------------------+
  293. | *Setter* | set_rotating(value) |
  294. +----------+---------------------+
  295. | *Getter* | is_rotating() |
  296. +----------+---------------------+
  297. If ``true``, the camera rotates with the target. Default value: ``false``
  298. ----
  299. .. _class_Camera2D_property_smoothing_enabled:
  300. - :ref:`bool<class_bool>` **smoothing_enabled**
  301. +----------+------------------------------------+
  302. | *Setter* | set_enable_follow_smoothing(value) |
  303. +----------+------------------------------------+
  304. | *Getter* | is_follow_smoothing_enabled() |
  305. +----------+------------------------------------+
  306. If ``true``, the camera smoothly moves towards the target at :ref:`smoothing_speed<class_Camera2D_property_smoothing_speed>`. Default value: ``false``
  307. ----
  308. .. _class_Camera2D_property_smoothing_speed:
  309. - :ref:`float<class_float>` **smoothing_speed**
  310. +----------+-----------------------------+
  311. | *Setter* | set_follow_smoothing(value) |
  312. +----------+-----------------------------+
  313. | *Getter* | get_follow_smoothing() |
  314. +----------+-----------------------------+
  315. Speed in pixels per second of the camera's smoothing effect when :ref:`smoothing_enabled<class_Camera2D_property_smoothing_enabled>` is ``true``
  316. ----
  317. .. _class_Camera2D_property_zoom:
  318. - :ref:`Vector2<class_Vector2>` **zoom**
  319. +----------+-----------------+
  320. | *Setter* | set_zoom(value) |
  321. +----------+-----------------+
  322. | *Getter* | get_zoom() |
  323. +----------+-----------------+
  324. The camera's zoom relative to the viewport. Values larger than ``Vector2(1, 1)`` zoom out and smaller values zoom in. For an example, use ``Vector2(0.5, 0.5)`` for a 2x zoom in, and ``Vector2(4, 4)`` for a 4x zoom out.
  325. Method Descriptions
  326. -------------------
  327. .. _class_Camera2D_method_align:
  328. - void **align** **(** **)**
  329. Align the camera to the tracked node
  330. ----
  331. .. _class_Camera2D_method_clear_current:
  332. - void **clear_current** **(** **)**
  333. Removes any ``Camera2D`` from the ancestor :ref:`Viewport<class_Viewport>`'s internal currently-assigned camera.
  334. ----
  335. .. _class_Camera2D_method_force_update_scroll:
  336. - void **force_update_scroll** **(** **)**
  337. Force the camera to update scroll immediately.
  338. ----
  339. .. _class_Camera2D_method_get_camera_position:
  340. - :ref:`Vector2<class_Vector2>` **get_camera_position** **(** **)** const
  341. Returns the camera position.
  342. ----
  343. .. _class_Camera2D_method_get_camera_screen_center:
  344. - :ref:`Vector2<class_Vector2>` **get_camera_screen_center** **(** **)** const
  345. Returns the location of the ``Camera2D``'s screen-center, relative to the origin.
  346. ----
  347. .. _class_Camera2D_method_make_current:
  348. - void **make_current** **(** **)**
  349. Make this the current 2D camera for the scene (viewport and layer), in case there's many cameras in the scene.
  350. ----
  351. .. _class_Camera2D_method_reset_smoothing:
  352. - void **reset_smoothing** **(** **)**
  353. Set the camera's position immediately to its current smoothing destination.
  354. This has no effect if smoothing is disabled.