CollisionObject2D.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="CollisionObject2D" inherits="Node2D" version="4.0">
  3. <brief_description>
  4. Base node for 2D collision objects.
  5. </brief_description>
  6. <description>
  7. CollisionObject2D is the base class for 2D physics objects. It can hold any number of 2D collision [Shape2D]s. Each shape must be assigned to a [i]shape owner[/i]. The CollisionObject2D can have any number of shape owners. Shape owners are not nodes and do not appear in the editor, but are accessible through code using the [code]shape_owner_*[/code] methods.
  8. </description>
  9. <tutorials>
  10. </tutorials>
  11. <methods>
  12. <method name="_input_event" qualifiers="virtual">
  13. <return type="void" />
  14. <argument index="0" name="viewport" type="Viewport" />
  15. <argument index="1" name="event" type="InputEvent" />
  16. <argument index="2" name="shape_idx" type="int" />
  17. <description>
  18. Accepts unhandled [InputEvent]s. Requires [member input_pickable] to be [code]true[/code]. [code]shape_idx[/code] is the child index of the clicked [Shape2D]. Connect to the [code]input_event[/code] signal to easily pick up these events.
  19. </description>
  20. </method>
  21. <method name="create_shape_owner">
  22. <return type="int" />
  23. <argument index="0" name="owner" type="Object" />
  24. <description>
  25. Creates a new shape owner for the given object. Returns [code]owner_id[/code] of the new owner for future reference.
  26. </description>
  27. </method>
  28. <method name="get_collision_layer_value" qualifiers="const">
  29. <return type="bool" />
  30. <argument index="0" name="layer_number" type="int" />
  31. <description>
  32. Returns whether or not the specified layer of the [member collision_layer] is enabled, given a [code]layer_number[/code] between 1 and 32.
  33. </description>
  34. </method>
  35. <method name="get_collision_mask_value" qualifiers="const">
  36. <return type="bool" />
  37. <argument index="0" name="layer_number" type="int" />
  38. <description>
  39. Returns whether or not the specified layer of the [member collision_mask] is enabled, given a [code]layer_number[/code] between 1 and 32.
  40. </description>
  41. </method>
  42. <method name="get_rid" qualifiers="const">
  43. <return type="RID" />
  44. <description>
  45. Returns the object's [RID].
  46. </description>
  47. </method>
  48. <method name="get_shape_owner_one_way_collision_margin" qualifiers="const">
  49. <return type="float" />
  50. <argument index="0" name="owner_id" type="int" />
  51. <description>
  52. Returns the [code]one_way_collision_margin[/code] of the shape owner identified by given [code]owner_id[/code].
  53. </description>
  54. </method>
  55. <method name="get_shape_owners">
  56. <return type="Array" />
  57. <description>
  58. Returns an [Array] of [code]owner_id[/code] identifiers. You can use these ids in other methods that take [code]owner_id[/code] as an argument.
  59. </description>
  60. </method>
  61. <method name="is_shape_owner_disabled" qualifiers="const">
  62. <return type="bool" />
  63. <argument index="0" name="owner_id" type="int" />
  64. <description>
  65. If [code]true[/code], the shape owner and its shapes are disabled.
  66. </description>
  67. </method>
  68. <method name="is_shape_owner_one_way_collision_enabled" qualifiers="const">
  69. <return type="bool" />
  70. <argument index="0" name="owner_id" type="int" />
  71. <description>
  72. Returns [code]true[/code] if collisions for the shape owner originating from this [CollisionObject2D] will not be reported to collided with [CollisionObject2D]s.
  73. </description>
  74. </method>
  75. <method name="remove_shape_owner">
  76. <return type="void" />
  77. <argument index="0" name="owner_id" type="int" />
  78. <description>
  79. Removes the given shape owner.
  80. </description>
  81. </method>
  82. <method name="set_collision_layer_value">
  83. <return type="void" />
  84. <argument index="0" name="layer_number" type="int" />
  85. <argument index="1" name="value" type="bool" />
  86. <description>
  87. Based on [code]value[/code], enables or disables the specified layer in the [member collision_layer], given a [code]layer_number[/code] between 1 and 32.
  88. </description>
  89. </method>
  90. <method name="set_collision_mask_value">
  91. <return type="void" />
  92. <argument index="0" name="layer_number" type="int" />
  93. <argument index="1" name="value" type="bool" />
  94. <description>
  95. Based on [code]value[/code], enables or disables the specified layer in the [member collision_mask], given a [code]layer_number[/code] between 1 and 32.
  96. </description>
  97. </method>
  98. <method name="shape_find_owner" qualifiers="const">
  99. <return type="int" />
  100. <argument index="0" name="shape_index" type="int" />
  101. <description>
  102. Returns the [code]owner_id[/code] of the given shape.
  103. </description>
  104. </method>
  105. <method name="shape_owner_add_shape">
  106. <return type="void" />
  107. <argument index="0" name="owner_id" type="int" />
  108. <argument index="1" name="shape" type="Shape2D" />
  109. <description>
  110. Adds a [Shape2D] to the shape owner.
  111. </description>
  112. </method>
  113. <method name="shape_owner_clear_shapes">
  114. <return type="void" />
  115. <argument index="0" name="owner_id" type="int" />
  116. <description>
  117. Removes all shapes from the shape owner.
  118. </description>
  119. </method>
  120. <method name="shape_owner_get_owner" qualifiers="const">
  121. <return type="Object" />
  122. <argument index="0" name="owner_id" type="int" />
  123. <description>
  124. Returns the parent object of the given shape owner.
  125. </description>
  126. </method>
  127. <method name="shape_owner_get_shape" qualifiers="const">
  128. <return type="Shape2D" />
  129. <argument index="0" name="owner_id" type="int" />
  130. <argument index="1" name="shape_id" type="int" />
  131. <description>
  132. Returns the [Shape2D] with the given id from the given shape owner.
  133. </description>
  134. </method>
  135. <method name="shape_owner_get_shape_count" qualifiers="const">
  136. <return type="int" />
  137. <argument index="0" name="owner_id" type="int" />
  138. <description>
  139. Returns the number of shapes the given shape owner contains.
  140. </description>
  141. </method>
  142. <method name="shape_owner_get_shape_index" qualifiers="const">
  143. <return type="int" />
  144. <argument index="0" name="owner_id" type="int" />
  145. <argument index="1" name="shape_id" type="int" />
  146. <description>
  147. Returns the child index of the [Shape2D] with the given id from the given shape owner.
  148. </description>
  149. </method>
  150. <method name="shape_owner_get_transform" qualifiers="const">
  151. <return type="Transform2D" />
  152. <argument index="0" name="owner_id" type="int" />
  153. <description>
  154. Returns the shape owner's [Transform2D].
  155. </description>
  156. </method>
  157. <method name="shape_owner_remove_shape">
  158. <return type="void" />
  159. <argument index="0" name="owner_id" type="int" />
  160. <argument index="1" name="shape_id" type="int" />
  161. <description>
  162. Removes a shape from the given shape owner.
  163. </description>
  164. </method>
  165. <method name="shape_owner_set_disabled">
  166. <return type="void" />
  167. <argument index="0" name="owner_id" type="int" />
  168. <argument index="1" name="disabled" type="bool" />
  169. <description>
  170. If [code]true[/code], disables the given shape owner.
  171. </description>
  172. </method>
  173. <method name="shape_owner_set_one_way_collision">
  174. <return type="void" />
  175. <argument index="0" name="owner_id" type="int" />
  176. <argument index="1" name="enable" type="bool" />
  177. <description>
  178. If [code]enable[/code] is [code]true[/code], collisions for the shape owner originating from this [CollisionObject2D] will not be reported to collided with [CollisionObject2D]s.
  179. </description>
  180. </method>
  181. <method name="shape_owner_set_one_way_collision_margin">
  182. <return type="void" />
  183. <argument index="0" name="owner_id" type="int" />
  184. <argument index="1" name="margin" type="float" />
  185. <description>
  186. Sets the [code]one_way_collision_margin[/code] of the shape owner identified by given [code]owner_id[/code] to [code]margin[/code] pixels.
  187. </description>
  188. </method>
  189. <method name="shape_owner_set_transform">
  190. <return type="void" />
  191. <argument index="0" name="owner_id" type="int" />
  192. <argument index="1" name="transform" type="Transform2D" />
  193. <description>
  194. Sets the [Transform2D] of the given shape owner.
  195. </description>
  196. </method>
  197. </methods>
  198. <members>
  199. <member name="collision_layer" type="int" setter="set_collision_layer" getter="get_collision_layer" default="1">
  200. The physics layers this CollisionObject2D is in. Collision objects can exist in one or more of 32 different layers. See also [member collision_mask].
  201. [b]Note:[/b] Object A can detect a contact with object B only if object B is in any of the layers that object A scans. See [url=https://docs.godotengine.org/en/latest/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information.
  202. </member>
  203. <member name="collision_mask" type="int" setter="set_collision_mask" getter="get_collision_mask" default="1">
  204. The physics layers this CollisionObject2D scans. Collision objects can scan one or more of 32 different layers. See also [member collision_layer].
  205. [b]Note:[/b] Object A can detect a contact with object B only if object B is in any of the layers that object A scans. See [url=https://docs.godotengine.org/en/latest/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information.
  206. </member>
  207. <member name="disable_mode" type="int" setter="set_disable_mode" getter="get_disable_mode" enum="CollisionObject2D.DisableMode" default="0">
  208. Defines the behavior in physics when [member Node.process_mode] is set to [constant Node.PROCESS_MODE_DISABLED]. See [enum DisableMode] for more details about the different modes.
  209. </member>
  210. <member name="input_pickable" type="bool" setter="set_pickable" getter="is_pickable" default="true">
  211. If [code]true[/code], this object is pickable. A pickable object can detect the mouse pointer entering/leaving, and if the mouse is inside it, report input events. Requires at least one [code]collision_layer[/code] bit to be set.
  212. </member>
  213. </members>
  214. <signals>
  215. <signal name="input_event">
  216. <argument index="0" name="viewport" type="Node" />
  217. <argument index="1" name="event" type="InputEvent" />
  218. <argument index="2" name="shape_idx" type="int" />
  219. <description>
  220. Emitted when an input event occurs. Requires [member input_pickable] to be [code]true[/code] and at least one [code]collision_layer[/code] bit to be set. See [method _input_event] for details.
  221. </description>
  222. </signal>
  223. <signal name="mouse_entered">
  224. <description>
  225. Emitted when the mouse pointer enters any of this object's shapes. Requires [member input_pickable] to be [code]true[/code] and at least one [member collision_layer] bit to be set. Note that moving between different shapes within a single [CollisionObject2D] won't cause this signal to be emitted.
  226. </description>
  227. </signal>
  228. <signal name="mouse_exited">
  229. <description>
  230. Emitted when the mouse pointer exits all this object's shapes. Requires [member input_pickable] to be [code]true[/code] and at least one [member collision_layer] bit to be set. Note that moving between different shapes within a single [CollisionObject2D] won't cause this signal to be emitted.
  231. </description>
  232. </signal>
  233. <signal name="mouse_shape_entered">
  234. <argument index="0" name="shape_idx" type="int" />
  235. <description>
  236. Emitted when the mouse pointer enters any of this object's shapes or moves from one shape to another. [code]shape_idx[/code] is the child index of the newly entered [Shape2D]. Requires [member input_pickable] to be [code]true[/code] and at least one [member collision_layer] bit to be set.
  237. </description>
  238. </signal>
  239. <signal name="mouse_shape_exited">
  240. <argument index="0" name="shape_idx" type="int" />
  241. <description>
  242. Emitted when the mouse pointer exits any of this object's shapes. [code]shape_idx[/code] is the child index of the exited [Shape2D]. Requires [member input_pickable] to be [code]true[/code] and at least one [member collision_layer] bit to be set.
  243. </description>
  244. </signal>
  245. </signals>
  246. <constants>
  247. <constant name="DISABLE_MODE_REMOVE" value="0" enum="DisableMode">
  248. When [member Node.process_mode] is set to [constant Node.PROCESS_MODE_DISABLED], remove from the physics simulation to stop all physics interactions with this [CollisionObject2D].
  249. Automatically re-added to the physics simulation when the [Node] is processed again.
  250. </constant>
  251. <constant name="DISABLE_MODE_MAKE_STATIC" value="1" enum="DisableMode">
  252. When [member Node.process_mode] is set to [constant Node.PROCESS_MODE_DISABLED], make the body static. Doesn't affect [Area2D]. [PhysicsBody2D] can't be affected by forces or other bodies while static.
  253. Automatically set [PhysicsBody2D] back to its original mode when the [Node] is processed again.
  254. </constant>
  255. <constant name="DISABLE_MODE_KEEP_ACTIVE" value="2" enum="DisableMode">
  256. When [member Node.process_mode] is set to [constant Node.PROCESS_MODE_DISABLED], do not affect the physics simulation.
  257. </constant>
  258. </constants>
  259. </class>