Skip to content
0.2.0-dev Download ZIP
309 lines ·17.2 KB Raw
1<?xml version="1.0" encoding="UTF-8" ?>
2<class name="CollisionObject2D" inherits="Node2D" api_type="core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3 <brief_description>
4 Abstract base class for 2D physics objects.
5 </brief_description>
6 <description>
7 Abstract base class for 2D physics objects. [CollisionObject2D] can hold any number of [Shape2D]s for collision. Each shape must be assigned to a [i]shape owner[/i]. 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 <param index="0" name="viewport" type="Viewport" />
16 <param index="1" name="event" type="InputEvent" />
17 <param index="2" name="shape_idx" type="int" />
18 <description>
19 Detects unhandled mouse and touch [InputEvent]s through [param event] when they happen while hovering over the object. Gesture events are not detected. [param viewport] is the [Viewport] that the event originated in (for viewports other than the main one to be detected, [member Viewport.physics_object_picking] needs to be set to [code]true[/code]). [param shape_idx] is the index of the detected shape from [PhysicsServer2D].
20 See also [method Node._unhandled_input], [method shape_find_owner], and [method shape_owner_get_owner].
21 [b]Note:[/b] [InputEventScreenDrag] events are triggered if the drag events started while hovering the object, or when the object is in the path of the drag event.
22 [b]Note:[/b] [method _input_event] requires [member input_pickable] to be [code]true[/code] and at least one [member collision_layer] bit to be set.
23 </description>
24 </method>
25 <method name="_mouse_enter" qualifiers="virtual">
26 <return type="void" />
27 <description>
28 Called 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 function to be called.
29 </description>
30 </method>
31 <method name="_mouse_exit" qualifiers="virtual">
32 <return type="void" />
33 <description>
34 Called 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 function to be called.
35 </description>
36 </method>
37 <method name="_mouse_shape_enter" qualifiers="virtual">
38 <return type="void" />
39 <param index="0" name="shape_idx" type="int" />
40 <description>
41 Called when the mouse pointer enters any of this object's shapes or moves from one shape to another. [param shape_idx] 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 called.
42 </description>
43 </method>
44 <method name="_mouse_shape_exit" qualifiers="virtual">
45 <return type="void" />
46 <param index="0" name="shape_idx" type="int" />
47 <description>
48 Called when the mouse pointer exits any of this object's shapes. [param shape_idx] 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 called.
49 </description>
50 </method>
51 <method name="create_shape_owner">
52 <return type="int" />
53 <param index="0" name="owner" type="Object" />
54 <description>
55 Creates a new shape owner for the given object. Returns [code]owner_id[/code] of the new owner for future reference.
56 </description>
57 </method>
58 <method name="get_collision_layer_value" qualifiers="const">
59 <return type="bool" />
60 <param index="0" name="layer_number" type="int" />
61 <description>
62 Returns whether or not the specified layer of the [member collision_layer] is enabled, given a [param layer_number] between 1 and 32. This simplifies editing this [CollisionObject2D]'s collision layer compared to assigning the [member collision_layer] property directly.
63 </description>
64 </method>
65 <method name="get_collision_mask_value" qualifiers="const">
66 <return type="bool" />
67 <param index="0" name="layer_number" type="int" />
68 <description>
69 Returns whether or not the specified layer of the [member collision_mask] is enabled, given a [param layer_number] between 1 and 32. This simplifies editing this [CollisionObject2D]'s collision mask compared to assigning the [member collision_mask] property directly.
70 </description>
71 </method>
72 <method name="get_rid" qualifiers="const">
73 <return type="RID" />
74 <description>
75 Returns the object's [RID].
76 </description>
77 </method>
78 <method name="get_shape_owner_one_way_collision_direction" qualifiers="const">
79 <return type="Vector2" />
80 <param index="0" name="owner_id" type="int" />
81 <description>
82 Returns the [code]one_way_collision_direction[/code] of the shape owner identified by the given [param owner_id].
83 </description>
84 </method>
85 <method name="get_shape_owner_one_way_collision_margin" qualifiers="const">
86 <return type="float" />
87 <param index="0" name="owner_id" type="int" />
88 <description>
89 Returns the [code]one_way_collision_margin[/code] of the shape owner identified by given [param owner_id].
90 </description>
91 </method>
92 <method name="get_shape_owners">
93 <return type="PackedInt32Array" />
94 <description>
95 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.
96 </description>
97 </method>
98 <method name="is_shape_owner_disabled" qualifiers="const">
99 <return type="bool" />
100 <param index="0" name="owner_id" type="int" />
101 <description>
102 If [code]true[/code], the shape owner and its shapes are disabled.
103 </description>
104 </method>
105 <method name="is_shape_owner_one_way_collision_enabled" qualifiers="const">
106 <return type="bool" />
107 <param index="0" name="owner_id" type="int" />
108 <description>
109 Returns [code]true[/code] if collisions for the shape owner originating from this [CollisionObject2D] will not be reported to collided with [CollisionObject2D]s.
110 </description>
111 </method>
112 <method name="remove_shape_owner">
113 <return type="void" />
114 <param index="0" name="owner_id" type="int" />
115 <description>
116 Removes the given shape owner.
117 </description>
118 </method>
119 <method name="set_collision_layer_value">
120 <return type="void" />
121 <param index="0" name="layer_number" type="int" />
122 <param index="1" name="value" type="bool" />
123 <description>
124 Based on [param value], enables or disables the specified layer in the [member collision_layer], given a [param layer_number] between 1 and 32.
125 </description>
126 </method>
127 <method name="set_collision_mask_value">
128 <return type="void" />
129 <param index="0" name="layer_number" type="int" />
130 <param index="1" name="value" type="bool" />
131 <description>
132 Based on [param value], enables or disables the specified layer in the [member collision_mask], given a [param layer_number] between 1 and 32.
133 </description>
134 </method>
135 <method name="shape_find_owner" qualifiers="const">
136 <return type="int" />
137 <param index="0" name="shape_index" type="int" />
138 <description>
139 Returns the [code]owner_id[/code] of the given shape.
140 </description>
141 </method>
142 <method name="shape_owner_add_shape">
143 <return type="void" />
144 <param index="0" name="owner_id" type="int" />
145 <param index="1" name="shape" type="Shape2D" />
146 <description>
147 Adds a [Shape2D] to the shape owner.
148 </description>
149 </method>
150 <method name="shape_owner_clear_shapes">
151 <return type="void" />
152 <param index="0" name="owner_id" type="int" />
153 <description>
154 Removes all shapes from the shape owner.
155 </description>
156 </method>
157 <method name="shape_owner_get_owner" qualifiers="const">
158 <return type="Object" />
159 <param index="0" name="owner_id" type="int" />
160 <description>
161 Returns the parent object of the given shape owner.
162 </description>
163 </method>
164 <method name="shape_owner_get_shape" qualifiers="const">
165 <return type="Shape2D" />
166 <param index="0" name="owner_id" type="int" />
167 <param index="1" name="shape_id" type="int" />
168 <description>
169 Returns the [Shape2D] with the given ID from the given shape owner.
170 </description>
171 </method>
172 <method name="shape_owner_get_shape_count" qualifiers="const">
173 <return type="int" />
174 <param index="0" name="owner_id" type="int" />
175 <description>
176 Returns the number of shapes the given shape owner contains.
177 </description>
178 </method>
179 <method name="shape_owner_get_shape_index" qualifiers="const">
180 <return type="int" />
181 <param index="0" name="owner_id" type="int" />
182 <param index="1" name="shape_id" type="int" />
183 <description>
184 Returns the child index of the [Shape2D] with the given ID from the given shape owner.
185 </description>
186 </method>
187 <method name="shape_owner_get_transform" qualifiers="const">
188 <return type="Transform2D" />
189 <param index="0" name="owner_id" type="int" />
190 <description>
191 Returns the shape owner's [Transform2D].
192 </description>
193 </method>
194 <method name="shape_owner_remove_shape">
195 <return type="void" />
196 <param index="0" name="owner_id" type="int" />
197 <param index="1" name="shape_id" type="int" />
198 <description>
199 Removes a shape from the given shape owner.
200 </description>
201 </method>
202 <method name="shape_owner_set_disabled">
203 <return type="void" />
204 <param index="0" name="owner_id" type="int" />
205 <param index="1" name="disabled" type="bool" />
206 <description>
207 If [code]true[/code], disables the given shape owner.
208 </description>
209 </method>
210 <method name="shape_owner_set_one_way_collision">
211 <return type="void" />
212 <param index="0" name="owner_id" type="int" />
213 <param index="1" name="enable" type="bool" />
214 <description>
215 If [param enable] is [code]true[/code], collisions for the shape owner originating from this [CollisionObject2D] will not be reported to collided with [CollisionObject2D]s.
216 </description>
217 </method>
218 <method name="shape_owner_set_one_way_collision_direction">
219 <return type="void" />
220 <param index="0" name="owner_id" type="int" />
221 <param index="1" name="direction" type="Vector2" />
222 <description>
223 Sets the [code]one_way_collision_direction[/code] of the shape owner identified by the given [param owner_id] to [param direction].
224 </description>
225 </method>
226 <method name="shape_owner_set_one_way_collision_margin">
227 <return type="void" />
228 <param index="0" name="owner_id" type="int" />
229 <param index="1" name="margin" type="float" />
230 <description>
231 Sets the [code]one_way_collision_margin[/code] of the shape owner identified by given [param owner_id] to [param margin] pixels.
232 </description>
233 </method>
234 <method name="shape_owner_set_transform">
235 <return type="void" />
236 <param index="0" name="owner_id" type="int" />
237 <param index="1" name="transform" type="Transform2D" />
238 <description>
239 Sets the [Transform2D] of the given shape owner.
240 </description>
241 </method>
242 </methods>
243 <members>
244 <member name="collision_layer" type="int" setter="set_collision_layer" getter="get_collision_layer" default="1">
245 The physics layers this CollisionObject2D is in. Collision objects can exist in one or more of 32 different layers. See also [member collision_mask]. For an easier way to change this value from a script, see [method set_collision_layer_value].
246 [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=$DOCS_URL/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information.
247 </member>
248 <member name="collision_mask" type="int" setter="set_collision_mask" getter="get_collision_mask" default="1">
249 The physics layers this CollisionObject2D scans. Collision objects can scan one or more of 32 different layers. See also [member collision_layer]. For an easier way to change this value from a script, see [method set_collision_mask_value].
250 [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=$DOCS_URL/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information.
251 </member>
252 <member name="collision_priority" type="float" setter="set_collision_priority" getter="get_collision_priority" default="1.0">
253 The priority used to solve colliding when occurring penetration. The higher the priority is, the lower the penetration into the object will be. This can for example be used to prevent the player from breaking through the boundaries of a level.
254 </member>
255 <member name="disable_mode" type="int" setter="set_disable_mode" getter="get_disable_mode" enum="CollisionObject2D.DisableMode" default="0">
256 Defines the behavior in physics when [member Node.process_mode] is set to [constant Node.PROCESS_MODE_DISABLED].
257 </member>
258 <member name="input_pickable" type="bool" setter="set_pickable" getter="is_pickable" default="true">
259 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.
260 </member>
261 </members>
262 <signals>
263 <signal name="input_event">
264 <param index="0" name="viewport" type="Node" />
265 <param index="1" name="event" type="InputEvent" />
266 <param index="2" name="shape_idx" type="int" />
267 <description>
268 Emitted when an unhandled input event occurs. Requires [member input_pickable] to be [code]true[/code] and at least one [member collision_layer] bit to be set. See [method _input_event] for details.
269 </description>
270 </signal>
271 <signal name="mouse_entered">
272 <description>
273 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.
274 [b]Note:[/b] Due to the lack of continuous collision detection, this signal may not be emitted in the expected order if the mouse moves fast enough and the [CollisionObject2D]'s area is small. This signal may also not be emitted if another [CollisionObject2D] is overlapping the [CollisionObject2D] in question.
275 </description>
276 </signal>
277 <signal name="mouse_exited">
278 <description>
279 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.
280 [b]Note:[/b] Due to the lack of continuous collision detection, this signal may not be emitted in the expected order if the mouse moves fast enough and the [CollisionObject2D]'s area is small. This signal may also not be emitted if another [CollisionObject2D] is overlapping the [CollisionObject2D] in question.
281 </description>
282 </signal>
283 <signal name="mouse_shape_entered">
284 <param index="0" name="shape_idx" type="int" />
285 <description>
286 Emitted when the mouse pointer enters any of this object's shapes or moves from one shape to another. [param shape_idx] 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.
287 </description>
288 </signal>
289 <signal name="mouse_shape_exited">
290 <param index="0" name="shape_idx" type="int" />
291 <description>
292 Emitted when the mouse pointer exits any of this object's shapes. [param shape_idx] 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.
293 </description>
294 </signal>
295 </signals>
296 <constants>
297 <constant name="DISABLE_MODE_REMOVE" value="0" enum="DisableMode">
298 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].
299 Automatically re-added to the physics simulation when the [Node] is processed again.
300 </constant>
301 <constant name="DISABLE_MODE_MAKE_STATIC" value="1" enum="DisableMode">
302 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.
303 Automatically set [PhysicsBody2D] back to its original mode when the [Node] is processed again.
304 </constant>
305 <constant name="DISABLE_MODE_KEEP_ACTIVE" value="2" enum="DisableMode">
306 When [member Node.process_mode] is set to [constant Node.PROCESS_MODE_DISABLED], do not affect the physics simulation.
307 </constant>
308 </constants>
309</class>