class_collisionobject2d.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. .. _class_CollisionObject2D:
  2. CollisionObject2D
  3. =================
  4. **Inherits:** :ref:`Node2D<class_node2d>`
  5. **Category:** Core
  6. Base node for 2D collisionables.
  7. Member Functions
  8. ----------------
  9. +----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  10. | void | :ref:`_input_event<class_CollisionObject2D__input_event>` **(** :ref:`Object<class_object>` viewport, :ref:`InputEvent<class_inputevent>` event, :ref:`int<class_int>` shape_idx **)** virtual |
  11. +----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  12. | void | :ref:`add_shape<class_CollisionObject2D_add_shape>` **(** :ref:`Shape2D<class_shape2d>` shape, :ref:`Matrix32<class_matrix32>` transform=1,0, 0,1, 0,0 **)** |
  13. +----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  14. | :ref:`int<class_int>` | :ref:`get_shape_count<class_CollisionObject2D_get_shape_count>` **(** **)** const |
  15. +----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  16. | void | :ref:`set_shape<class_CollisionObject2D_set_shape>` **(** :ref:`int<class_int>` shape_idx, :ref:`Shape<class_shape>` shape **)** |
  17. +----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  18. | void | :ref:`set_shape_transform<class_CollisionObject2D_set_shape_transform>` **(** :ref:`int<class_int>` shape_idx, :ref:`Matrix32<class_matrix32>` transform **)** |
  19. +----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  20. | void | :ref:`set_shape_as_trigger<class_CollisionObject2D_set_shape_as_trigger>` **(** :ref:`int<class_int>` shape_idx, :ref:`bool<class_bool>` enable **)** |
  21. +----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  22. | :ref:`Shape2D<class_shape2d>` | :ref:`get_shape<class_CollisionObject2D_get_shape>` **(** :ref:`int<class_int>` shape_idx **)** const |
  23. +----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`Matrix32<class_matrix32>` | :ref:`get_shape_transform<class_CollisionObject2D_get_shape_transform>` **(** :ref:`int<class_int>` shape_idx **)** const |
  25. +----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`bool<class_bool>` | :ref:`is_shape_set_as_trigger<class_CollisionObject2D_is_shape_set_as_trigger>` **(** :ref:`int<class_int>` shape_idx **)** const |
  27. +----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | void | :ref:`remove_shape<class_CollisionObject2D_remove_shape>` **(** :ref:`int<class_int>` shape_idx **)** |
  29. +----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | void | :ref:`clear_shapes<class_CollisionObject2D_clear_shapes>` **(** **)** |
  31. +----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`RID<class_rid>` | :ref:`get_rid<class_CollisionObject2D_get_rid>` **(** **)** const |
  33. +----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | void | :ref:`set_pickable<class_CollisionObject2D_set_pickable>` **(** :ref:`bool<class_bool>` enabled **)** |
  35. +----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`bool<class_bool>` | :ref:`is_pickable<class_CollisionObject2D_is_pickable>` **(** **)** const |
  37. +----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. Signals
  39. -------
  40. - **mouse_enter** **(** **)**
  41. - **input_event** **(** :ref:`Object<class_object>` viewport, :ref:`InputEvent<class_inputevent>` event, :ref:`int<class_int>` shape_idx **)**
  42. - **mouse_exit** **(** **)**
  43. Description
  44. -----------
  45. CollisionObject2D is the base class for 2D physics collisionables. They can hold any number of 2D collision shapes. Usually, they are edited by placing :ref:`CollisionShape2D<class_collisionshape2d>` and/or :ref:`CollisionPolygon2D<class_collisionpolygon2d>` nodes as children. Such nodes are for reference and not present outside the editor, so code should use the regular shape API.
  46. Member Function Description
  47. ---------------------------
  48. .. _class_CollisionObject2D__input_event:
  49. - void **_input_event** **(** :ref:`Object<class_object>` viewport, :ref:`InputEvent<class_inputevent>` event, :ref:`int<class_int>` shape_idx **)** virtual
  50. This method can be used to override normal input processing. The first parameter is the viewport where the event took place. The second holds the input event received, and the third the shape of this object where it happened.
  51. .. _class_CollisionObject2D_add_shape:
  52. - void **add_shape** **(** :ref:`Shape2D<class_shape2d>` shape, :ref:`Matrix32<class_matrix32>` transform=1,0, 0,1, 0,0 **)**
  53. Add a :ref:`Shape2D<class_shape2d>` to the collision body, with a given custom transform.
  54. .. _class_CollisionObject2D_get_shape_count:
  55. - :ref:`int<class_int>` **get_shape_count** **(** **)** const
  56. Return the amount of shapes in the collision body. Because a :ref:`CollisionPolygon2D<class_collisionpolygon2d>` can generate more than one :ref:`Shape2D<class_shape2d>`, the amount returned does not have to match the sum of :ref:`CollisionShape2D<class_collisionshape2d>` and :ref:`CollisionPolygon2D<class_collisionpolygon2d>`.
  57. .. _class_CollisionObject2D_set_shape:
  58. - void **set_shape** **(** :ref:`int<class_int>` shape_idx, :ref:`Shape<class_shape>` shape **)**
  59. Change a shape in the collision body.
  60. .. _class_CollisionObject2D_set_shape_transform:
  61. - void **set_shape_transform** **(** :ref:`int<class_int>` shape_idx, :ref:`Matrix32<class_matrix32>` transform **)**
  62. Change the shape transform in the collision body.
  63. .. _class_CollisionObject2D_set_shape_as_trigger:
  64. - void **set_shape_as_trigger** **(** :ref:`int<class_int>` shape_idx, :ref:`bool<class_bool>` enable **)**
  65. Set whether a shape is a trigger. A trigger shape detects collisions, but is otherwise unaffected by physics (i.e. colliding objects will not get blocked).
  66. .. _class_CollisionObject2D_get_shape:
  67. - :ref:`Shape2D<class_shape2d>` **get_shape** **(** :ref:`int<class_int>` shape_idx **)** const
  68. Return the shape in the given index.
  69. .. _class_CollisionObject2D_get_shape_transform:
  70. - :ref:`Matrix32<class_matrix32>` **get_shape_transform** **(** :ref:`int<class_int>` shape_idx **)** const
  71. Return the shape transform in the given index.
  72. .. _class_CollisionObject2D_is_shape_set_as_trigger:
  73. - :ref:`bool<class_bool>` **is_shape_set_as_trigger** **(** :ref:`int<class_int>` shape_idx **)** const
  74. Return whether a shape is a trigger. A trigger shape detects collisions, but is otherwise unaffected by physics (i.e. colliding objects will not get blocked).
  75. .. _class_CollisionObject2D_remove_shape:
  76. - void **remove_shape** **(** :ref:`int<class_int>` shape_idx **)**
  77. Remove the shape in the given index.
  78. .. _class_CollisionObject2D_clear_shapes:
  79. - void **clear_shapes** **(** **)**
  80. Remove all shapes.
  81. .. _class_CollisionObject2D_get_rid:
  82. - :ref:`RID<class_rid>` **get_rid** **(** **)** const
  83. Return the RID of this object.
  84. .. _class_CollisionObject2D_set_pickable:
  85. - void **set_pickable** **(** :ref:`bool<class_bool>` enabled **)**
  86. Set whether this object is pickable. A pickable object can detect the mouse pointer enter/leave it and, if the mouse is inside it, report input events.
  87. .. _class_CollisionObject2D_is_pickable:
  88. - :ref:`bool<class_bool>` **is_pickable** **(** **)** const
  89. Return whether this object is pickable.