CollisionObject2D
Inherits: Node2D < CanvasItem < Node < Object Inherited By: Area2D, PhysicsBody2D Base node for 2D collision objects.
Description
Shape2Ds. 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.
Note: 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.
Properties
Methods
Signals
- input_event ( Node viewport, InputEvent event, int shape_idx )
input_pickable to be
trueand at least onecollision_layerbit to be set. See _input_event for details.
- mouse_entered ( )
input_pickable to be
trueand at least onecollision_layerbit to be set.
- mouse_exited ( )
input_pickable to be
trueand at least onecollision_layerbit to be set.Property Descriptions
- int collision_layer collision_mask. Note: 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 Collision layers and masks in the documentation for more information.
- int collision_mask collision_layer. Note: 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 Collision layers and masks in the documentation for more information.
- bool input_pickable
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.Method Descriptions
- _input_event ( Object viewport, InputEvent event, int shape_idx ) virtual
InputEvents. Requires input_pickable to be
true.shape_idxis the child index of the clicked Shape2D. Connect to theinput_eventsignal to easily pick up these events.
- int create_shape_owner ( Object owner )
owner_idof the new owner for future reference.
- bool get_collision_layer_bit ( int bit ) const
bitof the collision_layer is set.
- bool get_collision_mask_bit ( int bit ) const
bitof the collision_mask is set.
- RID get_rid ( ) const RID.
- float get_shape_owner_one_way_collision_margin ( int owner_id ) const
one_way_collision_marginof the shape owner identified by givenowner_id.
- Array get_shape_owners ( )
Array of
owner_ididentifiers. You can use these ids in other methods that takeowner_idas an argument.
- bool is_shape_owner_disabled ( int owner_id ) const
true, the shape owner and its shapes are disabled.
- bool is_shape_owner_one_way_collision_enabled ( int owner_id ) const
trueif collisions for the shape owner originating from thisCollisionObject2Dwill not be reported to collided withCollisionObject2Ds.
- remove_shape_owner ( int owner_id ) Removes the given shape owner.
- set_collision_layer_bit ( int bit, bool value )
valueistrue, sets the specifiedbitin the the collision_layer.valueisfalse, clears the specifiedbitin the the collision_layer.
- set_collision_mask_bit ( int bit, bool value )
valueistrue, sets the specifiedbitin the the collision_mask.valueisfalse, clears the specifiedbitin the the collision_mask.
- int shape_find_owner ( int shape_index ) const
owner_idof the given shape.
- shape_owner_add_shape ( int owner_id, Shape2D shape ) Shape2D to the shape owner.
- shape_owner_clear_shapes ( int owner_id ) Removes all shapes from the shape owner.
- Object shape_owner_get_owner ( int owner_id ) const Returns the parent object of the given shape owner.
- Shape2D shape_owner_get_shape ( int owner_id, int shape_id ) const Shape2D with the given id from the given shape owner.
- int shape_owner_get_shape_count ( int owner_id ) const Returns the number of shapes the given shape owner contains.
- int shape_owner_get_shape_index ( int owner_id, int shape_id ) const Shape2D with the given id from the given shape owner.
- Transform2D shape_owner_get_transform ( int owner_id ) const Transform2D.
- shape_owner_remove_shape ( int owner_id, int shape_id ) Removes a shape from the given shape owner.
- shape_owner_set_disabled ( int owner_id, bool disabled )
true, disables the given shape owner.
- shape_owner_set_one_way_collision ( int owner_id, bool enable )
enableistrue, collisions for the shape owner originating from thisCollisionObject2Dwill not be reported to collided withCollisionObject2Ds.
- shape_owner_set_one_way_collision_margin ( int owner_id, float margin )
one_way_collision_marginof the shape owner identified by givenowner_idtomarginpixels.
- shape_owner_set_transform ( int owner_id, Transform2D transform ) Transform2D of the given shape owner.
