class_collisionobject2d.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the CollisionObject2D.xml source instead.
  3. .. The source is found in doc/classes or modules/<name>/doc_classes.
  4. .. _class_CollisionObject2D:
  5. CollisionObject2D
  6. =================
  7. **Inherits:** :ref:`Node2D<class_Node2D>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  8. **Inherited By:** :ref:`Area2D<class_Area2D>`, :ref:`PhysicsBody2D<class_PhysicsBody2D>`
  9. **Category:** Core
  10. Brief Description
  11. -----------------
  12. Base node for 2D collision objects.
  13. Properties
  14. ----------
  15. +-------------------------+------------------------------------------------------------------------+------+
  16. | :ref:`bool<class_bool>` | :ref:`input_pickable<class_CollisionObject2D_property_input_pickable>` | true |
  17. +-------------------------+------------------------------------------------------------------------+------+
  18. Methods
  19. -------
  20. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  21. | void | :ref:`_input_event<class_CollisionObject2D_method__input_event>` **(** :ref:`Object<class_Object>` viewport, :ref:`InputEvent<class_InputEvent>` event, :ref:`int<class_int>` shape_idx **)** virtual |
  22. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`int<class_int>` | :ref:`create_shape_owner<class_CollisionObject2D_method_create_shape_owner>` **(** :ref:`Object<class_Object>` owner **)** |
  24. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`RID<class_RID>` | :ref:`get_rid<class_CollisionObject2D_method_get_rid>` **(** **)** const |
  26. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`float<class_float>` | :ref:`get_shape_owner_one_way_collision_margin<class_CollisionObject2D_method_get_shape_owner_one_way_collision_margin>` **(** :ref:`int<class_int>` owner_id **)** const |
  28. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`Array<class_Array>` | :ref:`get_shape_owners<class_CollisionObject2D_method_get_shape_owners>` **(** **)** |
  30. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`bool<class_bool>` | :ref:`is_shape_owner_disabled<class_CollisionObject2D_method_is_shape_owner_disabled>` **(** :ref:`int<class_int>` owner_id **)** const |
  32. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`bool<class_bool>` | :ref:`is_shape_owner_one_way_collision_enabled<class_CollisionObject2D_method_is_shape_owner_one_way_collision_enabled>` **(** :ref:`int<class_int>` owner_id **)** const |
  34. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | void | :ref:`remove_shape_owner<class_CollisionObject2D_method_remove_shape_owner>` **(** :ref:`int<class_int>` owner_id **)** |
  36. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`int<class_int>` | :ref:`shape_find_owner<class_CollisionObject2D_method_shape_find_owner>` **(** :ref:`int<class_int>` shape_index **)** const |
  38. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | void | :ref:`shape_owner_add_shape<class_CollisionObject2D_method_shape_owner_add_shape>` **(** :ref:`int<class_int>` owner_id, :ref:`Shape2D<class_Shape2D>` shape **)** |
  40. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | void | :ref:`shape_owner_clear_shapes<class_CollisionObject2D_method_shape_owner_clear_shapes>` **(** :ref:`int<class_int>` owner_id **)** |
  42. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`Object<class_Object>` | :ref:`shape_owner_get_owner<class_CollisionObject2D_method_shape_owner_get_owner>` **(** :ref:`int<class_int>` owner_id **)** const |
  44. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`Shape2D<class_Shape2D>` | :ref:`shape_owner_get_shape<class_CollisionObject2D_method_shape_owner_get_shape>` **(** :ref:`int<class_int>` owner_id, :ref:`int<class_int>` shape_id **)** const |
  46. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`int<class_int>` | :ref:`shape_owner_get_shape_count<class_CollisionObject2D_method_shape_owner_get_shape_count>` **(** :ref:`int<class_int>` owner_id **)** const |
  48. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`int<class_int>` | :ref:`shape_owner_get_shape_index<class_CollisionObject2D_method_shape_owner_get_shape_index>` **(** :ref:`int<class_int>` owner_id, :ref:`int<class_int>` shape_id **)** const |
  50. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`Transform2D<class_Transform2D>` | :ref:`shape_owner_get_transform<class_CollisionObject2D_method_shape_owner_get_transform>` **(** :ref:`int<class_int>` owner_id **)** const |
  52. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | void | :ref:`shape_owner_remove_shape<class_CollisionObject2D_method_shape_owner_remove_shape>` **(** :ref:`int<class_int>` owner_id, :ref:`int<class_int>` shape_id **)** |
  54. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`shape_owner_set_disabled<class_CollisionObject2D_method_shape_owner_set_disabled>` **(** :ref:`int<class_int>` owner_id, :ref:`bool<class_bool>` disabled **)** |
  56. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`shape_owner_set_one_way_collision<class_CollisionObject2D_method_shape_owner_set_one_way_collision>` **(** :ref:`int<class_int>` owner_id, :ref:`bool<class_bool>` enable **)** |
  58. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | void | :ref:`shape_owner_set_one_way_collision_margin<class_CollisionObject2D_method_shape_owner_set_one_way_collision_margin>` **(** :ref:`int<class_int>` owner_id, :ref:`float<class_float>` margin **)** |
  60. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | void | :ref:`shape_owner_set_transform<class_CollisionObject2D_method_shape_owner_set_transform>` **(** :ref:`int<class_int>` owner_id, :ref:`Transform2D<class_Transform2D>` transform **)** |
  62. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. Signals
  64. -------
  65. .. _class_CollisionObject2D_signal_input_event:
  66. - **input_event** **(** :ref:`Node<class_Node>` viewport, :ref:`InputEvent<class_InputEvent>` event, :ref:`int<class_int>` shape_idx **)**
  67. Emitted when an input event occurs. Requires ``input_pickable`` to be ``true`` and at least one ``collision_layer`` bit to be set. See :ref:`_input_event<class_CollisionObject2D_method__input_event>` for details.
  68. .. _class_CollisionObject2D_signal_mouse_entered:
  69. - **mouse_entered** **(** **)**
  70. Emitted when the mouse pointer enters any of this object's shapes. Requires ``input_pickable`` to be ``true`` and at least one ``collision_layer`` bit to be set.
  71. .. _class_CollisionObject2D_signal_mouse_exited:
  72. - **mouse_exited** **(** **)**
  73. Emitted when the mouse pointer exits all this object's shapes. Requires ``input_pickable`` to be ``true`` and at least one ``collision_layer`` bit to be set.
  74. Description
  75. -----------
  76. CollisionObject2D is the base class for 2D physics objects. It can hold any number of 2D collision :ref:`Shape2D<class_Shape2D>`\ s. Each shape must be assigned to a *shape owner*. 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 ``shape_owner_*`` methods.
  77. Property Descriptions
  78. ---------------------
  79. .. _class_CollisionObject2D_property_input_pickable:
  80. - :ref:`bool<class_bool>` **input_pickable**
  81. +-----------+---------------------+
  82. | *Default* | true |
  83. +-----------+---------------------+
  84. | *Setter* | set_pickable(value) |
  85. +-----------+---------------------+
  86. | *Getter* | is_pickable() |
  87. +-----------+---------------------+
  88. If ``true``, 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 ``collision_layer`` bit to be set.
  89. Method Descriptions
  90. -------------------
  91. .. _class_CollisionObject2D_method__input_event:
  92. - void **_input_event** **(** :ref:`Object<class_Object>` viewport, :ref:`InputEvent<class_InputEvent>` event, :ref:`int<class_int>` shape_idx **)** virtual
  93. Accepts unhandled :ref:`InputEvent<class_InputEvent>`\ s. ``shape_idx`` is the child index of the clicked :ref:`Shape2D<class_Shape2D>`. Connect to the ``input_event`` signal to easily pick up these events.
  94. .. _class_CollisionObject2D_method_create_shape_owner:
  95. - :ref:`int<class_int>` **create_shape_owner** **(** :ref:`Object<class_Object>` owner **)**
  96. Creates a new shape owner for the given object. Returns ``owner_id`` of the new owner for future reference.
  97. .. _class_CollisionObject2D_method_get_rid:
  98. - :ref:`RID<class_RID>` **get_rid** **(** **)** const
  99. Returns the object's :ref:`RID<class_RID>`.
  100. .. _class_CollisionObject2D_method_get_shape_owner_one_way_collision_margin:
  101. - :ref:`float<class_float>` **get_shape_owner_one_way_collision_margin** **(** :ref:`int<class_int>` owner_id **)** const
  102. .. _class_CollisionObject2D_method_get_shape_owners:
  103. - :ref:`Array<class_Array>` **get_shape_owners** **(** **)**
  104. Returns an :ref:`Array<class_Array>` of ``owner_id`` identifiers. You can use these ids in other methods that take ``owner_id`` as an argument.
  105. .. _class_CollisionObject2D_method_is_shape_owner_disabled:
  106. - :ref:`bool<class_bool>` **is_shape_owner_disabled** **(** :ref:`int<class_int>` owner_id **)** const
  107. If ``true``, the shape owner and its shapes are disabled.
  108. .. _class_CollisionObject2D_method_is_shape_owner_one_way_collision_enabled:
  109. - :ref:`bool<class_bool>` **is_shape_owner_one_way_collision_enabled** **(** :ref:`int<class_int>` owner_id **)** const
  110. Returns ``true`` if collisions for the shape owner originating from this ``CollisionObject2D`` will not be reported to collided with ``CollisionObject2D``\ s.
  111. .. _class_CollisionObject2D_method_remove_shape_owner:
  112. - void **remove_shape_owner** **(** :ref:`int<class_int>` owner_id **)**
  113. Removes the given shape owner.
  114. .. _class_CollisionObject2D_method_shape_find_owner:
  115. - :ref:`int<class_int>` **shape_find_owner** **(** :ref:`int<class_int>` shape_index **)** const
  116. Returns the ``owner_id`` of the given shape.
  117. .. _class_CollisionObject2D_method_shape_owner_add_shape:
  118. - void **shape_owner_add_shape** **(** :ref:`int<class_int>` owner_id, :ref:`Shape2D<class_Shape2D>` shape **)**
  119. Adds a :ref:`Shape2D<class_Shape2D>` to the shape owner.
  120. .. _class_CollisionObject2D_method_shape_owner_clear_shapes:
  121. - void **shape_owner_clear_shapes** **(** :ref:`int<class_int>` owner_id **)**
  122. Removes all shapes from the shape owner.
  123. .. _class_CollisionObject2D_method_shape_owner_get_owner:
  124. - :ref:`Object<class_Object>` **shape_owner_get_owner** **(** :ref:`int<class_int>` owner_id **)** const
  125. Returns the parent object of the given shape owner.
  126. .. _class_CollisionObject2D_method_shape_owner_get_shape:
  127. - :ref:`Shape2D<class_Shape2D>` **shape_owner_get_shape** **(** :ref:`int<class_int>` owner_id, :ref:`int<class_int>` shape_id **)** const
  128. Returns the :ref:`Shape2D<class_Shape2D>` with the given id from the given shape owner.
  129. .. _class_CollisionObject2D_method_shape_owner_get_shape_count:
  130. - :ref:`int<class_int>` **shape_owner_get_shape_count** **(** :ref:`int<class_int>` owner_id **)** const
  131. Returns the number of shapes the given shape owner contains.
  132. .. _class_CollisionObject2D_method_shape_owner_get_shape_index:
  133. - :ref:`int<class_int>` **shape_owner_get_shape_index** **(** :ref:`int<class_int>` owner_id, :ref:`int<class_int>` shape_id **)** const
  134. Returns the child index of the :ref:`Shape2D<class_Shape2D>` with the given id from the given shape owner.
  135. .. _class_CollisionObject2D_method_shape_owner_get_transform:
  136. - :ref:`Transform2D<class_Transform2D>` **shape_owner_get_transform** **(** :ref:`int<class_int>` owner_id **)** const
  137. Returns the shape owner's :ref:`Transform2D<class_Transform2D>`.
  138. .. _class_CollisionObject2D_method_shape_owner_remove_shape:
  139. - void **shape_owner_remove_shape** **(** :ref:`int<class_int>` owner_id, :ref:`int<class_int>` shape_id **)**
  140. Removes a shape from the given shape owner.
  141. .. _class_CollisionObject2D_method_shape_owner_set_disabled:
  142. - void **shape_owner_set_disabled** **(** :ref:`int<class_int>` owner_id, :ref:`bool<class_bool>` disabled **)**
  143. If ``true``, disables the given shape owner.
  144. .. _class_CollisionObject2D_method_shape_owner_set_one_way_collision:
  145. - void **shape_owner_set_one_way_collision** **(** :ref:`int<class_int>` owner_id, :ref:`bool<class_bool>` enable **)**
  146. If ``enable`` is ``true``, collisions for the shape owner originating from this ``CollisionObject2D`` will not be reported to collided with ``CollisionObject2D``\ s.
  147. .. _class_CollisionObject2D_method_shape_owner_set_one_way_collision_margin:
  148. - void **shape_owner_set_one_way_collision_margin** **(** :ref:`int<class_int>` owner_id, :ref:`float<class_float>` margin **)**
  149. .. _class_CollisionObject2D_method_shape_owner_set_transform:
  150. - void **shape_owner_set_transform** **(** :ref:`int<class_int>` owner_id, :ref:`Transform2D<class_Transform2D>` transform **)**
  151. Sets the :ref:`Transform2D<class_Transform2D>` of the given shape owner.