class_area2d.rst 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the doc/base/classes.xml source instead.
  3. .. _class_Area2D:
  4. Area2D
  5. ======
  6. **Inherits:** :ref:`CollisionObject2D<class_collisionobject2d>` **<** :ref:`Node2D<class_node2d>` **<** :ref:`CanvasItem<class_canvasitem>` **<** :ref:`Node<class_node>` **<** :ref:`Object<class_object>`
  7. **Category:** Core
  8. Brief Description
  9. -----------------
  10. General purpose area detection and influence for 2D physics.
  11. Member Functions
  12. ----------------
  13. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  14. | void | :ref:`set_space_override_mode<class_Area2D_set_space_override_mode>` **(** :ref:`int<class_int>` enable **)** |
  15. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  16. | :ref:`int<class_int>` | :ref:`get_space_override_mode<class_Area2D_get_space_override_mode>` **(** **)** const |
  17. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  18. | void | :ref:`set_gravity_is_point<class_Area2D_set_gravity_is_point>` **(** :ref:`bool<class_bool>` enable **)** |
  19. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  20. | :ref:`bool<class_bool>` | :ref:`is_gravity_a_point<class_Area2D_is_gravity_a_point>` **(** **)** const |
  21. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  22. | void | :ref:`set_gravity_distance_scale<class_Area2D_set_gravity_distance_scale>` **(** :ref:`float<class_float>` distance_scale **)** |
  23. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`float<class_float>` | :ref:`get_gravity_distance_scale<class_Area2D_get_gravity_distance_scale>` **(** **)** const |
  25. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  26. | void | :ref:`set_gravity_vector<class_Area2D_set_gravity_vector>` **(** :ref:`Vector2<class_vector2>` vector **)** |
  27. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`Vector2<class_vector2>` | :ref:`get_gravity_vector<class_Area2D_get_gravity_vector>` **(** **)** const |
  29. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  30. | void | :ref:`set_gravity<class_Area2D_set_gravity>` **(** :ref:`float<class_float>` gravity **)** |
  31. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`float<class_float>` | :ref:`get_gravity<class_Area2D_get_gravity>` **(** **)** const |
  33. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  34. | void | :ref:`set_linear_damp<class_Area2D_set_linear_damp>` **(** :ref:`float<class_float>` linear_damp **)** |
  35. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`float<class_float>` | :ref:`get_linear_damp<class_Area2D_get_linear_damp>` **(** **)** const |
  37. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  38. | void | :ref:`set_angular_damp<class_Area2D_set_angular_damp>` **(** :ref:`float<class_float>` angular_damp **)** |
  39. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`float<class_float>` | :ref:`get_angular_damp<class_Area2D_get_angular_damp>` **(** **)** const |
  41. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  42. | void | :ref:`set_priority<class_Area2D_set_priority>` **(** :ref:`float<class_float>` priority **)** |
  43. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`float<class_float>` | :ref:`get_priority<class_Area2D_get_priority>` **(** **)** const |
  45. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  46. | void | :ref:`set_collision_mask<class_Area2D_set_collision_mask>` **(** :ref:`int<class_int>` collision_mask **)** |
  47. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`int<class_int>` | :ref:`get_collision_mask<class_Area2D_get_collision_mask>` **(** **)** const |
  49. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  50. | void | :ref:`set_layer_mask<class_Area2D_set_layer_mask>` **(** :ref:`int<class_int>` layer_mask **)** |
  51. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`int<class_int>` | :ref:`get_layer_mask<class_Area2D_get_layer_mask>` **(** **)** const |
  53. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  54. | void | :ref:`set_collision_mask_bit<class_Area2D_set_collision_mask_bit>` **(** :ref:`int<class_int>` bit, :ref:`bool<class_bool>` value **)** |
  55. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`bool<class_bool>` | :ref:`get_collision_mask_bit<class_Area2D_get_collision_mask_bit>` **(** :ref:`int<class_int>` bit **)** const |
  57. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  58. | void | :ref:`set_layer_mask_bit<class_Area2D_set_layer_mask_bit>` **(** :ref:`int<class_int>` bit, :ref:`bool<class_bool>` value **)** |
  59. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`bool<class_bool>` | :ref:`get_layer_mask_bit<class_Area2D_get_layer_mask_bit>` **(** :ref:`int<class_int>` bit **)** const |
  61. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  62. | void | :ref:`set_enable_monitoring<class_Area2D_set_enable_monitoring>` **(** :ref:`bool<class_bool>` enable **)** |
  63. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`bool<class_bool>` | :ref:`is_monitoring_enabled<class_Area2D_is_monitoring_enabled>` **(** **)** const |
  65. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  66. | void | :ref:`set_monitorable<class_Area2D_set_monitorable>` **(** :ref:`bool<class_bool>` enable **)** |
  67. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  68. | :ref:`bool<class_bool>` | :ref:`is_monitorable<class_Area2D_is_monitorable>` **(** **)** const |
  69. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`Array<class_array>` | :ref:`get_overlapping_bodies<class_Area2D_get_overlapping_bodies>` **(** **)** const |
  71. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`Array<class_array>` | :ref:`get_overlapping_areas<class_Area2D_get_overlapping_areas>` **(** **)** const |
  73. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`bool<class_bool>` | :ref:`overlaps_body<class_Area2D_overlaps_body>` **(** :ref:`Object<class_object>` body **)** const |
  75. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  76. | :ref:`bool<class_bool>` | :ref:`overlaps_area<class_Area2D_overlaps_area>` **(** :ref:`Object<class_object>` area **)** const |
  77. +--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  78. Signals
  79. -------
  80. - **body_enter** **(** :ref:`Object<class_object>` body **)**
  81. - **body_enter_shape** **(** :ref:`int<class_int>` body_id, :ref:`Object<class_object>` body, :ref:`int<class_int>` body_shape, :ref:`int<class_int>` area_shape **)**
  82. - **area_enter** **(** :ref:`Object<class_object>` area **)**
  83. - **area_enter_shape** **(** :ref:`int<class_int>` area_id, :ref:`Object<class_object>` area, :ref:`int<class_int>` area_shape, :ref:`int<class_int>` area_shape **)**
  84. - **body_exit** **(** :ref:`Object<class_object>` body **)**
  85. - **body_exit_shape** **(** :ref:`int<class_int>` body_id, :ref:`Object<class_object>` body, :ref:`int<class_int>` body_shape, :ref:`int<class_int>` area_shape **)**
  86. - **area_exit** **(** :ref:`Object<class_object>` area **)**
  87. - **area_exit_shape** **(** :ref:`int<class_int>` area_id, :ref:`Object<class_object>` area, :ref:`int<class_int>` area_shape, :ref:`int<class_int>` area_shape **)**
  88. Description
  89. -----------
  90. General purpose area detection for 2D physics. Areas can be used for detection of objects that enter/exit them, as well as overriding space parameters (changing gravity, damping, etc). For this, use any space override different from AREA_SPACE_OVERRIDE_DISABLE and point gravity at the center of mass.
  91. Member Function Description
  92. ---------------------------
  93. .. _class_Area2D_set_space_override_mode:
  94. - void **set_space_override_mode** **(** :ref:`int<class_int>` enable **)**
  95. Set the space override mode. This mode controls how an area affects gravity and damp.
  96. AREA_SPACE_OVERRIDE_DISABLED: This area does not affect gravity/damp. These are generally areas that exist only to detect collisions, and objects entering or exiting them.
  97. AREA_SPACE_OVERRIDE_COMBINE: This area adds its gravity/damp values to whatever has been calculated so far. This way, many overlapping areas can combine their physics to make interesting effects.
  98. AREA_SPACE_OVERRIDE_COMBINE_REPLACE: This area adds its gravity/damp values to whatever has been calculated so far. Then stops taking into account the rest of the areas, even the default one.
  99. AREA_SPACE_OVERRIDE_REPLACE: This area replaces any gravity/damp, even the default one, and stops taking into account the rest of the areas.
  100. AREA_SPACE_OVERRIDE_REPLACE_COMBINE: This area replaces any gravity/damp calculated so far, but keeps calculating the rest of the areas, down to the default one.
  101. .. _class_Area2D_get_space_override_mode:
  102. - :ref:`int<class_int>` **get_space_override_mode** **(** **)** const
  103. Return the space override mode.
  104. .. _class_Area2D_set_gravity_is_point:
  105. - void **set_gravity_is_point** **(** :ref:`bool<class_bool>` enable **)**
  106. When overriding space parameters, this method sets whether this area has a center of gravity. To set/get the location of the center of gravity, use :ref:`set_gravity_vector<class_Area2D_set_gravity_vector>`/:ref:`get_gravity_vector<class_Area2D_get_gravity_vector>`.
  107. .. _class_Area2D_is_gravity_a_point:
  108. - :ref:`bool<class_bool>` **is_gravity_a_point** **(** **)** const
  109. Return whether gravity is a point. A point gravity will attract objects towards it, as opposed to a gravity vector, which moves them in a given direction.
  110. .. _class_Area2D_set_gravity_distance_scale:
  111. - void **set_gravity_distance_scale** **(** :ref:`float<class_float>` distance_scale **)**
  112. Set the falloff factor for point gravity. The greater this value is, the faster the strength of gravity decreases with the square of distance.
  113. .. _class_Area2D_get_gravity_distance_scale:
  114. - :ref:`float<class_float>` **get_gravity_distance_scale** **(** **)** const
  115. Return the falloff factor for point gravity.
  116. .. _class_Area2D_set_gravity_vector:
  117. - void **set_gravity_vector** **(** :ref:`Vector2<class_vector2>` vector **)**
  118. Set the gravity vector. This vector does not have to be normalized.
  119. If gravity is a point (see :ref:`is_gravity_a_point<class_Area2D_is_gravity_a_point>`), this will be the attraction center.
  120. .. _class_Area2D_get_gravity_vector:
  121. - :ref:`Vector2<class_vector2>` **get_gravity_vector** **(** **)** const
  122. Return the gravity vector. If gravity is a point (see :ref:`is_gravity_a_point<class_Area2D_is_gravity_a_point>`), this will be the attraction center.
  123. .. _class_Area2D_set_gravity:
  124. - void **set_gravity** **(** :ref:`float<class_float>` gravity **)**
  125. Set the gravity intensity. This is useful to alter the force of gravity without altering its direction.
  126. This value multiplies the gravity vector, whether it is the given vector (:ref:`set_gravity_vector<class_Area2D_set_gravity_vector>`), or a calculated one (when using a center of gravity).
  127. .. _class_Area2D_get_gravity:
  128. - :ref:`float<class_float>` **get_gravity** **(** **)** const
  129. Return the gravity intensity.
  130. .. _class_Area2D_set_linear_damp:
  131. - void **set_linear_damp** **(** :ref:`float<class_float>` linear_damp **)**
  132. Set the rate at which objects stop moving in this area, if there are not any other forces moving it. The value is a fraction of its current speed, lost per second. Thus, a value of 1.0 should mean stopping immediately, and 0.0 means the object never stops.
  133. In practice, as the fraction of speed lost gets smaller with each frame, a value of 1.0 does not mean the object will stop in exactly one second. Only when the physics calculations are done at 1 frame per second, it does stop in a second.
  134. .. _class_Area2D_get_linear_damp:
  135. - :ref:`float<class_float>` **get_linear_damp** **(** **)** const
  136. Return the linear damp rate.
  137. .. _class_Area2D_set_angular_damp:
  138. - void **set_angular_damp** **(** :ref:`float<class_float>` angular_damp **)**
  139. Set the rate at which objects stop spinning in this area, if there are not any other forces making it spin. The value is a fraction of its current speed, lost per second. Thus, a value of 1.0 should mean stopping immediately, and 0.0 means the object never stops.
  140. In practice, as the fraction of speed lost gets smaller with each frame, a value of 1.0 does not mean the object will stop in exactly one second. Only when the physics calculations are done at 1 frame per second, it does stop in a second.
  141. .. _class_Area2D_get_angular_damp:
  142. - :ref:`float<class_float>` **get_angular_damp** **(** **)** const
  143. Return the angular damp rate.
  144. .. _class_Area2D_set_priority:
  145. - void **set_priority** **(** :ref:`float<class_float>` priority **)**
  146. Set the order in which the area is processed. Greater values mean the area gets processed first. This is useful for areas which have an space override different from AREA_SPACE_OVERRIDE_DISABLED or AREA_SPACE_OVERRIDE_COMBINE, as they replace values, and are thus order-dependent.
  147. Areas with the same priority value get evaluated in an unpredictable order, and should be differentiated if evaluation order is to be important.
  148. .. _class_Area2D_get_priority:
  149. - :ref:`float<class_float>` **get_priority** **(** **)** const
  150. Return the processing order of this area.
  151. .. _class_Area2D_set_collision_mask:
  152. - void **set_collision_mask** **(** :ref:`int<class_int>` collision_mask **)**
  153. Set the physics layers this area can scan for collisions.
  154. .. _class_Area2D_get_collision_mask:
  155. - :ref:`int<class_int>` **get_collision_mask** **(** **)** const
  156. Return the physics layers this area can scan for collisions.
  157. .. _class_Area2D_set_layer_mask:
  158. - void **set_layer_mask** **(** :ref:`int<class_int>` layer_mask **)**
  159. Set the physics layers this area is in.
  160. Collidable objects can exist in any of 32 different layers. These layers are not visual, but more of a tagging system instead. A collidable can use these layers/tags to select with which objects it can collide, using :ref:`set_collision_mask<class_Area2D_set_collision_mask>`.
  161. A contact is detected if object A is in any of the layers that object B scans, or object B is in any layer scanned by object A.
  162. .. _class_Area2D_get_layer_mask:
  163. - :ref:`int<class_int>` **get_layer_mask** **(** **)** const
  164. Return the physics layer this area is in.
  165. .. _class_Area2D_set_collision_mask_bit:
  166. - void **set_collision_mask_bit** **(** :ref:`int<class_int>` bit, :ref:`bool<class_bool>` value **)**
  167. Set/clear individual bits on the collision mask. This makes selecting the areas scanned easier.
  168. .. _class_Area2D_get_collision_mask_bit:
  169. - :ref:`bool<class_bool>` **get_collision_mask_bit** **(** :ref:`int<class_int>` bit **)** const
  170. Return an individual bit on the collision mask.
  171. .. _class_Area2D_set_layer_mask_bit:
  172. - void **set_layer_mask_bit** **(** :ref:`int<class_int>` bit, :ref:`bool<class_bool>` value **)**
  173. Set/clear individual bits on the layer mask. This makes getting an area in/out of only one layer easier.
  174. .. _class_Area2D_get_layer_mask_bit:
  175. - :ref:`bool<class_bool>` **get_layer_mask_bit** **(** :ref:`int<class_int>` bit **)** const
  176. Return an individual bit on the layer mask.
  177. .. _class_Area2D_set_enable_monitoring:
  178. - void **set_enable_monitoring** **(** :ref:`bool<class_bool>` enable **)**
  179. Set whether this area can detect bodies/areas entering/exiting it.
  180. .. _class_Area2D_is_monitoring_enabled:
  181. - :ref:`bool<class_bool>` **is_monitoring_enabled** **(** **)** const
  182. Return whether this area detects bodies/areas entering/exiting it.
  183. .. _class_Area2D_set_monitorable:
  184. - void **set_monitorable** **(** :ref:`bool<class_bool>` enable **)**
  185. Set whether this area can be detected by other, monitoring, areas. Only areas need to be marked as monitorable. Bodies are always so.
  186. .. _class_Area2D_is_monitorable:
  187. - :ref:`bool<class_bool>` **is_monitorable** **(** **)** const
  188. Return whether this area can be detected by other, monitoring, areas.
  189. .. _class_Area2D_get_overlapping_bodies:
  190. - :ref:`Array<class_array>` **get_overlapping_bodies** **(** **)** const
  191. Return a list of the bodies (:ref:`PhysicsBody2D<class_physicsbody2d>`) that are totally or partially inside this area.
  192. .. _class_Area2D_get_overlapping_areas:
  193. - :ref:`Array<class_array>` **get_overlapping_areas** **(** **)** const
  194. Return a list of the areas that are totally or partially inside this area.
  195. .. _class_Area2D_overlaps_body:
  196. - :ref:`bool<class_bool>` **overlaps_body** **(** :ref:`Object<class_object>` body **)** const
  197. Return whether the body passed is totally or partially inside this area.
  198. .. _class_Area2D_overlaps_area:
  199. - :ref:`bool<class_bool>` **overlaps_area** **(** :ref:`Object<class_object>` area **)** const
  200. Return whether the area passed is totally or partially inside this area.