|
Axmol 3.0.0-89d6d9a
|
A shape for body. More...
#include <Collider2D.h>
Inherits Object.
Inherited by BoxCollider2D, CircleCollider2D, EdgeBoxCollider2D, EdgeChainCollider2D, EdgePolygonCollider2D, EdgeSegmentCollider2D, and PolygonCollider2D.
Public Types | |
| enum class | Type { } |
Public Member Functions | |
| Rigidbody2D * | getAttachedBody () const |
| Get the body that this shape attaches. | |
| Type | getType () const |
| Return this shape's type. | |
| void | setTag (unsigned int tag) |
| Set this shape's tag. | |
| unsigned int | getTag () const |
| Get this shape's tag. | |
| float | getDensity () const |
| Get this shape's density. | |
| void | setDensity (float density, bool apply=true) |
| Set this shape's density. | |
| float | getRestitution () const |
| Get this shape's restitution. | |
| void | setRestitution (float restitution, bool apply=true) |
| Set this shape's restitution. | |
| float | getFriction () const |
| Get this shape's friction. | |
| void | setFriction (float friction, bool apply=true) |
| Set this shape's friction. | |
| const PhysicsMaterial2D & | getMaterial () const |
| Get this shape's PhysicsMaterial2D object. | |
| void | setMaterial (const PhysicsMaterial2D &material) |
| Set this shape's material. | |
| bool | isSensor () const |
| Check whether this collider is configured as a sensor. | |
| void | setSensor (bool sensor) |
| Enable or disable sensor behavior for this collider. | |
| bool | isEventEnabled (ContactEventBits events) const |
| Check whether one or more event types are enabled for this collider. | |
| void | setEventEnabled (ContactEventBits events, bool enabled) |
| Enable or disable one or more event types for this collider. | |
| void | refreshEventFlags () |
| Re-applies the effective event mask to all attached native shapes. | |
| virtual Vec2 | getOffset () |
| Get this shape's position offset. | |
| virtual Vec2 | getCenter () |
| Get this shape's center position. | |
| bool | containsPoint (const Vec2 &point) const |
| Test point is inside this shape or not. | |
| void | setCategoryBits (uint64_t categoryBits) |
| Set a mask that defines which categories this physics body belongs to. | |
| uint64_t | getCategoryBits () const |
| Get a mask that defines which categories this physics body belongs to. | |
| void | setMaskBits (uint64_t maskBits) |
| A mask that defines which categories of physics bodies can collide with this physics body. | |
| uint64_t | getMaskBits () const |
| Get a mask that defines which categories of physics bodies can collide with this physics body. | |
| void | setGroup (int groupIndex) |
| Set the group of body. | |
| int | getGroup () const |
| Get the group of body. | |
| Public Member Functions inherited from Object | |
| void | retain () |
| Retains the ownership. | |
| void | release () |
| Releases the ownership immediately. | |
| Object * | autorelease () |
| Releases the ownership sometime soon automatically. | |
| unsigned int | getReferenceCount () const |
| Returns the Object's current reference count. | |
| uint64_t | getObjectID () const noexcept |
| Returns the process-local diagnostic identifier assigned at construction. | |
| virtual | ~Object () |
| Destructor. | |
Static Public Member Functions | |
| static void | recenterPoints (Vec2 *points, int count, const Vec2 ¢er=Vec2::zero) |
| Move the points to the center. | |
| static Vec2 | getPolygonCenter (std::span< const Vec2 > points) |
| Get center of the polygon points. | |
A shape for body.
You do not create PhysicsWorld2D objects directly, instead, you can view Rigidbody2D to see how to create it.
|
strong |
|
inline |
Get the body that this shape attaches.
|
inline |
Set this shape's tag.
| tag | An integer number that identifies a shape object. |
|
inline |
Get this shape's tag.
|
inline |
Get this shape's density.
| void setDensity | ( | float | density, |
| bool | apply = true ) |
Set this shape's density.
It will change the body's mass this shape attaches.
| density | A float number. |
|
inline |
Get this shape's restitution.
| void setRestitution | ( | float | restitution, |
| bool | apply = true ) |
Set this shape's restitution.
It will change the shape's elasticity.
| restitution | A float number. |
|
inline |
Get this shape's friction.
| void setFriction | ( | float | friction, |
| bool | apply = true ) |
Set this shape's friction.
It will change the shape's friction.
| friction | A float number. |
|
inline |
Get this shape's PhysicsMaterial2D object.
| void setMaterial | ( | const PhysicsMaterial2D & | material | ) |
Set this shape's material.
It will change the shape's mass, elasticity and friction.
| material | A PhysicsMaterial2D object. |
|
inline |
Check whether this collider is configured as a sensor.
A sensor collider generates overlap events but never produces a collision response. Sensors are useful for detecting triggers, zones, or one-way interactions.
| void setSensor | ( | bool | sensor | ) |
Enable or disable sensor behavior for this collider.
A sensor collider generates overlap events but does not produce collision responses. This setting must be applied before the owning rigid-body component is added to a node, as sensor state cannot be modified at runtime afterward.
| sensor | True to enable sensor behavior, false to disable. |
| bool isEventEnabled | ( | ContactEventBits | events | ) | const |
Check whether one or more event types are enabled for this collider.
This method verifies if the specified event bits are fully enabled in the collider. You can pass a single event (e.g., ContactEventBits::PreSolve) or a combination of events (e.g., ContactEventBits::PreSolve | ContactEventBits::Contact).
| events | The event bits to check. |
| void setEventEnabled | ( | ContactEventBits | events, |
| bool | enabled ) |
Enable or disable one or more event types for this collider.
This method allows toggling specific event bits. You can enable or disable a single event or multiple events at once by combining flags.
| events | The event bits to modify. |
| enabled | True to enable the specified events, false to disable them. |
| void refreshEventFlags | ( | ) |
Re-applies the effective event mask to all attached native shapes.
This combines the collider-local event flags with the owning world's global event mask and is used when either side changes at runtime.
|
inlinevirtual |
Get this shape's position offset.
This function should be overridden in inherit classes.
Reimplemented in BoxCollider2D, CircleCollider2D, and EdgeBoxCollider2D.
|
inlinevirtual |
Get this shape's center position.
This function should be overridden in inherit classes.
Reimplemented in EdgeChainCollider2D, EdgePolygonCollider2D, EdgeSegmentCollider2D, and PolygonCollider2D.
| bool containsPoint | ( | const Vec2 & | point | ) | const |
|
static |
| void setCategoryBits | ( | uint64_t | categoryBits | ) |
Set a mask that defines which categories this physics body belongs to.
Every physics body in a scene can be assigned to up to 64 different categories, each corresponding to a bit in the bit mask. You define the mask values used in your game. In conjunction with the collisionBits and contactTestBits properties, you define which physics bodies interact with each other and when your game is notified of these interactions.
| categoryBits | An integer number, the default value is UINT64_MAX (all bits set). |
|
inline |
Get a mask that defines which categories this physics body belongs to.
| void setMaskBits | ( | uint64_t | maskBits | ) |
A mask that defines which categories of physics bodies can collide with this physics body.
When two physics bodies contact each other, a collision may occur. This body's collision mask is compared to the other body's category mask by performing a logical AND operation. If the result is a non-zero value, then this body is affected by the collision. Each body independently chooses whether it wants to be affected by the other body. For example, you might use this to avoid collision calculations that would make negligible changes to a body's velocity.
| maskBits | An integer number, the default value is UINT64_MAX (all bits set). |
|
inline |
Get a mask that defines which categories of physics bodies can collide with this physics body.
| void setGroup | ( | int | groupIndex | ) |
Set the group of body.
Collision groups let you specify an integral group index. You can have all fixtures with the same group index always collide (positive index) or never collide (negative index).
| groupIndex | An integer number, it have high priority than bit masks. |
|
inline |
Get the group of body.