CollisionObject2D.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="CollisionObject2D" inherits="Node2D" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
  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. [b]Note:[/b] Only collisions between objects within the same canvas ([Viewport] canvas or [CanvasLayer]) are supported. The behavior of collisions between objects in different canvases is undefined.
  9. </description>
  10. <tutorials>
  11. </tutorials>
  12. <methods>
  13. <method name="_input_event" qualifiers="virtual">
  14. <return type="void" />
  15. <argument index="0" name="viewport" type="Object" />
  16. <argument index="1" name="event" type="InputEvent" />
  17. <argument index="2" name="shape_idx" type="int" />
  18. <description>
  19. 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.
  20. </description>
  21. </method>
  22. <method name="create_shape_owner">
  23. <return type="int" />
  24. <argument index="0" name="owner" type="Object" />
  25. <description>
  26. Creates a new shape owner for the given object. Returns [code]owner_id[/code] of the new owner for future reference.
  27. </description>
  28. </method>
  29. <method name="get_collision_layer_bit" qualifiers="const">
  30. <return type="bool" />
  31. <argument index="0" name="bit" type="int" />
  32. <description>
  33. Returns whether or not the specified [code]bit[/code] of the [member collision_layer] is set.
  34. </description>
  35. </method>
  36. <method name="get_collision_mask_bit" qualifiers="const">
  37. <return type="bool" />
  38. <argument index="0" name="bit" type="int" />
  39. <description>
  40. Returns whether or not the specified [code]bit[/code] of the [member collision_mask] is set.
  41. </description>
  42. </method>
  43. <method name="get_rid" qualifiers="const">
  44. <return type="RID" />
  45. <description>
  46. Returns the object's [RID].
  47. </description>
  48. </method>
  49. <method name="get_shape_owner_one_way_collision_margin" qualifiers="const">
  50. <return type="float" />
  51. <argument index="0" name="owner_id" type="int" />
  52. <description>
  53. Returns the [code]one_way_collision_margin[/code] of the shape owner identified by given [code]owner_id[/code].
  54. </description>
  55. </method>
  56. <method name="get_shape_owners">
  57. <return type="Array" />
  58. <description>
  59. 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.
  60. </description>
  61. </method>
  62. <method name="is_shape_owner_disabled" qualifiers="const">
  63. <return type="bool" />
  64. <argument index="0" name="owner_id" type="int" />
  65. <description>
  66. If [code]true[/code], the shape owner and its shapes are disabled.
  67. </description>
  68. </method>
  69. <method name="is_shape_owner_one_way_collision_enabled" qualifiers="const">
  70. <return type="bool" />
  71. <argument index="0" name="owner_id" type="int" />
  72. <description>
  73. Returns [code]true[/code] if collisions for the shape owner originating from this [CollisionObject2D] will not be reported to collided with [CollisionObject2D]s.
  74. </description>
  75. </method>
  76. <method name="remove_shape_owner">
  77. <return type="void" />
  78. <argument index="0" name="owner_id" type="int" />
  79. <description>
  80. Removes the given shape owner.
  81. </description>
  82. </method>
  83. <method name="set_collision_layer_bit">
  84. <return type="void" />
  85. <argument index="0" name="bit" type="int" />
  86. <argument index="1" name="value" type="bool" />
  87. <description>
  88. If [code]value[/code] is [code]true[/code], sets the specified [code]bit[/code] in the [member collision_layer].
  89. If [code]value[/code] is [code]false[/code], clears the specified [code]bit[/code] in the [member collision_layer].
  90. </description>
  91. </method>
  92. <method name="set_collision_mask_bit">
  93. <return type="void" />
  94. <argument index="0" name="bit" type="int" />
  95. <argument index="1" name="value" type="bool" />
  96. <description>
  97. If [code]value[/code] is [code]true[/code], sets the specified [code]bit[/code] in the [member collision_mask].
  98. If [code]value[/code] is [code]false[/code], clears the specified [code]bit[/code] in the [member collision_mask].
  99. </description>
  100. </method>
  101. <method name="shape_find_owner" qualifiers="const">
  102. <return type="int" />
  103. <argument index="0" name="shape_index" type="int" />
  104. <description>
  105. Returns the [code]owner_id[/code] of the given shape.
  106. </description>
  107. </method>
  108. <method name="shape_owner_add_shape">
  109. <return type="void" />
  110. <argument index="0" name="owner_id" type="int" />
  111. <argument index="1" name="shape" type="Shape2D" />
  112. <description>
  113. Adds a [Shape2D] to the shape owner.
  114. </description>
  115. </method>
  116. <method name="shape_owner_clear_shapes">
  117. <return type="void" />
  118. <argument index="0" name="owner_id" type="int" />
  119. <description>
  120. Removes all shapes from the shape owner.
  121. </description>
  122. </method>
  123. <method name="shape_owner_get_owner" qualifiers="const">
  124. <return type="Object" />
  125. <argument index="0" name="owner_id" type="int" />
  126. <description>
  127. Returns the parent object of the given shape owner.
  128. </description>
  129. </method>
  130. <method name="shape_owner_get_shape" qualifiers="const">
  131. <return type="Shape2D" />
  132. <argument index="0" name="owner_id" type="int" />
  133. <argument index="1" name="shape_id" type="int" />
  134. <description>
  135. Returns the [Shape2D] with the given id from the given shape owner.
  136. </description>
  137. </method>
  138. <method name="shape_owner_get_shape_count" qualifiers="const">
  139. <return type="int" />
  140. <argument index="0" name="owner_id" type="int" />
  141. <description>
  142. Returns the number of shapes the given shape owner contains.
  143. </description>
  144. </method>
  145. <method name="shape_owner_get_shape_index" qualifiers="const">
  146. <return type="int" />
  147. <argument index="0" name="owner_id" type="int" />
  148. <argument index="1" name="shape_id" type="int" />
  149. <description>
  150. Returns the child index of the [Shape2D] with the given id from the given shape owner.
  151. </description>
  152. </method>
  153. <method name="shape_owner_get_transform" qualifiers="const">
  154. <return type="Transform2D" />
  155. <argument index="0" name="owner_id" type="int" />
  156. <description>
  157. Returns the shape owner's [Transform2D].
  158. </description>
  159. </method>
  160. <method name="shape_owner_remove_shape">
  161. <return type="void" />
  162. <argument index="0" name="owner_id" type="int" />
  163. <argument index="1" name="shape_id" type="int" />
  164. <description>
  165. Removes a shape from the given shape owner.
  166. </description>
  167. </method>
  168. <method name="shape_owner_set_disabled">
  169. <return type="void" />
  170. <argument index="0" name="owner_id" type="int" />
  171. <argument index="1" name="disabled" type="bool" />
  172. <description>
  173. If [code]true[/code], disables the given shape owner.
  174. </description>
  175. </method>
  176. <method name="shape_owner_set_one_way_collision">
  177. <return type="void" />
  178. <argument index="0" name="owner_id" type="int" />
  179. <argument index="1" name="enable" type="bool" />
  180. <description>
  181. 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.
  182. </description>
  183. </method>
  184. <method name="shape_owner_set_one_way_collision_margin">
  185. <return type="void" />
  186. <argument index="0" name="owner_id" type="int" />
  187. <argument index="1" name="margin" type="float" />
  188. <description>
  189. Sets the [code]one_way_collision_margin[/code] of the shape owner identified by given [code]owner_id[/code] to [code]margin[/code] pixels.
  190. </description>
  191. </method>
  192. <method name="shape_owner_set_transform">
  193. <return type="void" />
  194. <argument index="0" name="owner_id" type="int" />
  195. <argument index="1" name="transform" type="Transform2D" />
  196. <description>
  197. Sets the [Transform2D] of the given shape owner.
  198. </description>
  199. </method>
  200. </methods>
  201. <members>
  202. <member name="collision_layer" type="int" setter="set_collision_layer" getter="get_collision_layer" default="1">
  203. The physics layers this CollisionObject2D is in. Collision objects can exist in one or more of 32 different layers. See also [member collision_mask].
  204. [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=$DOCS_URL/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information.
  205. </member>
  206. <member name="collision_mask" type="int" setter="set_collision_mask" getter="get_collision_mask" default="1">
  207. The physics layers this CollisionObject2D scans. Collision objects can scan one or more of 32 different layers. See also [member collision_layer].
  208. [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=$DOCS_URL/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information.
  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 [member collision_layer] 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 [code]collision_layer[/code] bit to be set.
  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 [code]collision_layer[/code] bit to be set.
  231. </description>
  232. </signal>
  233. </signals>
  234. <constants>
  235. </constants>
  236. </class>