Axmol 3.0.0-89d6d9a
Loading...
Searching...
No Matches
Collider2D Class Referenceabstract

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 &center=Vec2::zero)
 Move the points to the center.
static Vec2 getPolygonCenter (std::span< const Vec2 > points)
 Get center of the polygon points.

Detailed Description

A shape for body.

You do not create PhysicsWorld2D objects directly, instead, you can view Rigidbody2D to see how to create it.

Member Enumeration Documentation

◆ Type

enum class Type
strong
Enumerator
POLYGEN 
EDGEPOLYGEN 

Member Function Documentation

◆ getAttachedBody()

Rigidbody2D * getAttachedBody ( ) const
inline

Get the body that this shape attaches.

Returns
A Rigidbody2D object pointer.

◆ getType()

Type getType ( ) const
inline

Return this shape's type.

Returns
A Type object.

◆ setTag()

void setTag ( unsigned int tag)
inline

Set this shape's tag.

Parameters
tagAn integer number that identifies a shape object.

◆ getTag()

unsigned int getTag ( ) const
inline

Get this shape's tag.

Returns
An integer number.

◆ getDensity()

float getDensity ( ) const
inline

Get this shape's density.

Returns
A float number.

◆ setDensity()

void setDensity ( float density,
bool apply = true )

Set this shape's density.

It will change the body's mass this shape attaches.

Parameters
densityA float number.

◆ getRestitution()

float getRestitution ( ) const
inline

Get this shape's restitution.

Returns
A float number.

◆ setRestitution()

void setRestitution ( float restitution,
bool apply = true )

Set this shape's restitution.

It will change the shape's elasticity.

Parameters
restitutionA float number.

◆ getFriction()

float getFriction ( ) const
inline

Get this shape's friction.

Returns
A float number.

◆ setFriction()

void setFriction ( float friction,
bool apply = true )

Set this shape's friction.

It will change the shape's friction.

Parameters
frictionA float number.

◆ getMaterial()

const PhysicsMaterial2D & getMaterial ( ) const
inline

Get this shape's PhysicsMaterial2D object.

Returns
A PhysicsMaterial2D object reference.

◆ setMaterial()

void setMaterial ( const PhysicsMaterial2D & material)

Set this shape's material.

It will change the shape's mass, elasticity and friction.

Parameters
materialA PhysicsMaterial2D object.

◆ isSensor()

bool isSensor ( ) const
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.

Returns
True if this collider is a sensor, false otherwise.

◆ setSensor()

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.

Parameters
sensorTrue to enable sensor behavior, false to disable.

◆ isEventEnabled()

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).

Parameters
eventsThe event bits to check.
Returns
True if all specified events are enabled, false otherwise.

◆ setEventEnabled()

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.

Parameters
eventsThe event bits to modify.
enabledTrue to enable the specified events, false to disable them.

◆ refreshEventFlags()

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.

◆ getOffset()

virtual Vec2 getOffset ( )
inlinevirtual

Get this shape's position offset.

This function should be overridden in inherit classes.

Returns
A Vec2 object.

Reimplemented in BoxCollider2D, CircleCollider2D, and EdgeBoxCollider2D.

◆ getCenter()

virtual Vec2 getCenter ( )
inlinevirtual

Get this shape's center position.

This function should be overridden in inherit classes.

Returns
A Vec2 object.

Reimplemented in EdgeChainCollider2D, EdgePolygonCollider2D, EdgeSegmentCollider2D, and PolygonCollider2D.

◆ containsPoint()

bool containsPoint ( const Vec2 & point) const

Test point is inside this shape or not.

Parameters
pointA Vec2 object.
Returns
A bool object.

◆ recenterPoints()

void recenterPoints ( Vec2 * points,
int count,
const Vec2 & center = Vec2::zero )
static

Move the points to the center.

Parameters
pointsA Vec2 object pointer.
countAn integer number.
centerA Vec2 object, default value is Vec2(0,0).

◆ getPolygonCenter()

Vec2 getPolygonCenter ( std::span< const Vec2 > points)
static

Get center of the polygon points.

Parameters
pointsA Vec2 object pointer.
countAn integer number.
Returns
A Vec2 object.

◆ setCategoryBits()

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.

Parameters
categoryBitsAn integer number, the default value is UINT64_MAX (all bits set).

◆ getCategoryBits()

uint64_t getCategoryBits ( ) const
inline

Get a mask that defines which categories this physics body belongs to.

Returns
An integer number.

◆ setMaskBits()

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.

Parameters
maskBitsAn integer number, the default value is UINT64_MAX (all bits set).

◆ getMaskBits()

uint64_t getMaskBits ( ) const
inline

Get a mask that defines which categories of physics bodies can collide with this physics body.

Returns
An integer number.

◆ setGroup()

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).

Parameters
groupIndexAn integer number, it have high priority than bit masks.

◆ getGroup()

int getGroup ( ) const
inline

Get the group of body.

Returns
An integer number.

The documentation for this class was generated from the following file:
  • Collider2D.h