CollisionObject2D.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="CollisionObject2D" inherits="Node2D" version="3.4">
  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="Object" />
  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_bit" qualifiers="const">
  29. <return type="bool" />
  30. <argument index="0" name="bit" type="int" />
  31. <description>
  32. Returns whether or not the specified [code]bit[/code] of the [member collision_layer] is set.
  33. </description>
  34. </method>
  35. <method name="get_collision_mask_bit" qualifiers="const">
  36. <return type="bool" />
  37. <argument index="0" name="bit" type="int" />
  38. <description>
  39. Returns whether or not the specified [code]bit[/code] of the [member collision_mask] is set.
  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_bit">
  83. <return type="void" />
  84. <argument index="0" name="bit" type="int" />
  85. <argument index="1" name="value" type="bool" />
  86. <description>
  87. If [code]value[/code] is [code]true[/code], sets the specified [code]bit[/code] in the the [member collision_layer].
  88. If [code]value[/code] is [code]false[/code], clears the specified [code]bit[/code] in the the [member collision_layer].
  89. </description>
  90. </method>
  91. <method name="set_collision_mask_bit">
  92. <return type="void" />
  93. <argument index="0" name="bit" type="int" />
  94. <argument index="1" name="value" type="bool" />
  95. <description>
  96. If [code]value[/code] is [code]true[/code], sets the specified [code]bit[/code] in the the [member collision_mask].
  97. If [code]value[/code] is [code]false[/code], clears the specified [code]bit[/code] in the the [member collision_mask].
  98. </description>
  99. </method>
  100. <method name="shape_find_owner" qualifiers="const">
  101. <return type="int" />
  102. <argument index="0" name="shape_index" type="int" />
  103. <description>
  104. Returns the [code]owner_id[/code] of the given shape.
  105. </description>
  106. </method>
  107. <method name="shape_owner_add_shape">
  108. <return type="void" />
  109. <argument index="0" name="owner_id" type="int" />
  110. <argument index="1" name="shape" type="Shape2D" />
  111. <description>
  112. Adds a [Shape2D] to the shape owner.
  113. </description>
  114. </method>
  115. <method name="shape_owner_clear_shapes">
  116. <return type="void" />
  117. <argument index="0" name="owner_id" type="int" />
  118. <description>
  119. Removes all shapes from the shape owner.
  120. </description>
  121. </method>
  122. <method name="shape_owner_get_owner" qualifiers="const">
  123. <return type="Object" />
  124. <argument index="0" name="owner_id" type="int" />
  125. <description>
  126. Returns the parent object of the given shape owner.
  127. </description>
  128. </method>
  129. <method name="shape_owner_get_shape" qualifiers="const">
  130. <return type="Shape2D" />
  131. <argument index="0" name="owner_id" type="int" />
  132. <argument index="1" name="shape_id" type="int" />
  133. <description>
  134. Returns the [Shape2D] with the given id from the given shape owner.
  135. </description>
  136. </method>
  137. <method name="shape_owner_get_shape_count" qualifiers="const">
  138. <return type="int" />
  139. <argument index="0" name="owner_id" type="int" />
  140. <description>
  141. Returns the number of shapes the given shape owner contains.
  142. </description>
  143. </method>
  144. <method name="shape_owner_get_shape_index" qualifiers="const">
  145. <return type="int" />
  146. <argument index="0" name="owner_id" type="int" />
  147. <argument index="1" name="shape_id" type="int" />
  148. <description>
  149. Returns the child index of the [Shape2D] with the given id from the given shape owner.
  150. </description>
  151. </method>
  152. <method name="shape_owner_get_transform" qualifiers="const">
  153. <return type="Transform2D" />
  154. <argument index="0" name="owner_id" type="int" />
  155. <description>
  156. Returns the shape owner's [Transform2D].
  157. </description>
  158. </method>
  159. <method name="shape_owner_remove_shape">
  160. <return type="void" />
  161. <argument index="0" name="owner_id" type="int" />
  162. <argument index="1" name="shape_id" type="int" />
  163. <description>
  164. Removes a shape from the given shape owner.
  165. </description>
  166. </method>
  167. <method name="shape_owner_set_disabled">
  168. <return type="void" />
  169. <argument index="0" name="owner_id" type="int" />
  170. <argument index="1" name="disabled" type="bool" />
  171. <description>
  172. If [code]true[/code], disables the given shape owner.
  173. </description>
  174. </method>
  175. <method name="shape_owner_set_one_way_collision">
  176. <return type="void" />
  177. <argument index="0" name="owner_id" type="int" />
  178. <argument index="1" name="enable" type="bool" />
  179. <description>
  180. 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.
  181. </description>
  182. </method>
  183. <method name="shape_owner_set_one_way_collision_margin">
  184. <return type="void" />
  185. <argument index="0" name="owner_id" type="int" />
  186. <argument index="1" name="margin" type="float" />
  187. <description>
  188. Sets the [code]one_way_collision_margin[/code] of the shape owner identified by given [code]owner_id[/code] to [code]margin[/code] pixels.
  189. </description>
  190. </method>
  191. <method name="shape_owner_set_transform">
  192. <return type="void" />
  193. <argument index="0" name="owner_id" type="int" />
  194. <argument index="1" name="transform" type="Transform2D" />
  195. <description>
  196. Sets the [Transform2D] of the given shape owner.
  197. </description>
  198. </method>
  199. </methods>
  200. <members>
  201. <member name="collision_layer" type="int" setter="set_collision_layer" getter="get_collision_layer" default="1">
  202. The physics layers this CollisionObject2D is in. Collision objects can exist in one or more of 32 different layers. See also [member collision_mask].
  203. [b]Note:[/b] A contact is detected if object A is in any of the layers that object B scans, or object B is in any 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.
  204. </member>
  205. <member name="collision_mask" type="int" setter="set_collision_mask" getter="get_collision_mask" default="1">
  206. The physics layers this CollisionObject2D scans. Collision objects can scan one or more of 32 different layers. See also [member collision_layer].
  207. [b]Note:[/b] A contact is detected if object A is in any of the layers that object B scans, or object B is in any 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.
  208. </member>
  209. <member name="input_pickable" type="bool" setter="set_pickable" getter="is_pickable" default="true">
  210. 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.
  211. </member>
  212. </members>
  213. <signals>
  214. <signal name="input_event">
  215. <argument index="0" name="viewport" type="Node" />
  216. <argument index="1" name="event" type="InputEvent" />
  217. <argument index="2" name="shape_idx" type="int" />
  218. <description>
  219. 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.
  220. </description>
  221. </signal>
  222. <signal name="mouse_entered">
  223. <description>
  224. 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 [code]collision_layer[/code] bit to be set.
  225. </description>
  226. </signal>
  227. <signal name="mouse_exited">
  228. <description>
  229. Emitted when the mouse pointer exits all this object's shapes. Requires [member input_pickable] to be [code]true[/code] and at least one [code]collision_layer[/code] bit to be set.
  230. </description>
  231. </signal>
  232. </signals>
  233. <constants>
  234. </constants>
  235. </class>