Capycore Engine  0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
Loading...
Searching...
No Matches
CircleCollider2D Class Reference

A 2D circle collider component that defines a circular collision shape for a GameObject. More...

#include <circle_collider_2d.h>

Inheritance diagram for CircleCollider2D:
[legend]

Public Member Functions

 CircleCollider2D (float friction, float bounciness, float radius=default_circle_collider_radius, Point offset={0.0f, 0.0f}, bool is_sensor=false, bool is_bullet=false)
 
 ~CircleCollider2D () override=default
 
void update (float dt) override
 
float radius () const noexcept
 
CircleCollider2Dradius (float value) noexcept
 
CircleCollider2Dfriction (float value) noexcept override
 
CircleCollider2Dbounciness (float value) noexcept override
 
std::string type_name () const override
 Provides a consistent type name for the component.
 
Point offset () const noexcept override
 
CircleCollider2Doffset (Point value) noexcept override
 
- Public Member Functions inherited from Collider2D
 Collider2D (float friction=default_friction_2d, float bounciness=default_bounciness_2d, Point offset={0.0f, 0.0f})
 
 ~Collider2D () override=default
 
void update (float dt) override
 
void on_trigger_enter (Collider2D &other)
 Called when another collider enters this collider's trigger area.
 
size_t add_on_trigger_enter (const std::function< void(Collider2D &, Collider2D &)> &action)
 
void remove_on_trigger_enter (int index)
 
void on_trigger_exit (Collider2D &other)
 Called when another collider exits this collider's trigger area.
 
size_t add_on_trigger_exit (const std::function< void(Collider2D &, Collider2D &)> &action)
 
void remove_on_trigger_exit (int index)
 
void on_collision_enter (Collider2D &other)
 Called when another collider exits this collider's trigger area.
 
size_t add_on_collision_enter (const std::function< void(Collider2D &, Collider2D &)> &action)
 
void remove_on_collision_enter (int index)
 
void on_collision_exit (Collider2D &other)
 Called when another collider exits this collider's trigger area.
 
size_t add_on_collision_exit (const std::function< void(Collider2D &, Collider2D &)> &action)
 
void remove_on_collision_exit (int index)
 
BodyDistance2D distance (Collider2D &other, bool use_fixture=false)
 Calculate the distance to another collider.
 
ColliderRayResult raycast (const Point &direction, float max_distance)
 Perform a raycast from this collider in a specified direction.
 
std::reference_wrapper< Rigidbody2Dget_rigidbody ()
 
float friction () const noexcept
 
float bounciness () const noexcept
 
PhysicsCreationFlagscreation_flags () noexcept
 
Collider2Dcreation_flags (PhysicsCreationFlags value) noexcept
 
std::string type_name () const override
 Provides a consistent type name for the component.
 
- Public Member Functions inherited from Renderable
 Renderable ()
 
 Renderable (int layer)
 
 ~Renderable () override=default
 
Renderableorder_in_layer (int layer)
 
int order_in_layer () const
 
void set_render_strategy (Component &component)
 
virtual IRenderingStrategyrender_strategy () const
 
std::string type_name () const override
 Provides a consistent type name for the component.
 
Renderabledisable_draw () noexcept
 
Renderableenable_draw () noexcept
 
bool should_draw () const noexcept
 
- Public Member Functions inherited from Component
 Component ()
 
virtual ~Component ()=default
 
bool active () const noexcept
 Checks if the component is active.
 
Componentactive (bool value) noexcept
 
bool marked_for_deletion () const noexcept
 Activates the component.
 
Componentmark_for_deletion () noexcept
 
virtual void on_attach ()
 Called when the component is attached to a GameObject.
 
virtual void on_detach ()
 Called when the component is detached from a GameObject.
 
virtual void on_serialize (std::vector< uint8_t > &) const
 Serializes the component's state into a byte array.
 
virtual void on_deserialize (const std::vector< uint8_t > &, size_t &)
 Deserializes the component's state from a byte array.
 
const std::optional< std::reference_wrapper< GameObject > > & parent () const noexcept
 Gets the parent GameObject of this component.
 
std::optional< std::reference_wrapper< GameObject > > & parent () noexcept
 Gets the parent GameObject of this component.
 
Componentparent (GameObject &parent)
 
Componentparent (std::nullopt_t nullopt)
 
size_t add_on_attach (const std::function< void(Component &)> &action)
 Retrieves the type information of the component.
 
void remove_on_attach (size_t index)
 
size_t add_on_detach (const std::function< void(Component &)> &action)
 Adds an action to be performed when the component is attached.
 
void remove_on_detach (size_t index)
 

Additional Inherited Members

- Protected Attributes inherited from Collider2D
PhysicsCreationFlags creation_flags_ {}
 
float friction_
 
float bounciness_
 
Point offset_
 
- Protected Attributes inherited from Renderable
std::unique_ptr< IRenderingStrategyrender_strategy_
 
int ordering_layer_ = 0
 
bool draw {true}
 

Detailed Description

A 2D circle collider component that defines a circular collision shape for a GameObject.

This component extends the Collider2D class to provide a circle-shaped collider, enabling circular collision detection and response within the physics engine.

Usage:

  • Create a CircleCollider2D component with desired properties.
  • Attach the CircleCollider2D to a GameObject to enable circular collision detection.
  • Modify properties such as radius, friction, bounciness, offset, sensor status, and bullet status as needed.
    Note
    Ensure the GameObject has a Rigidbody2D component for proper physics interaction.

Constructor & Destructor Documentation

◆ CircleCollider2D()

CircleCollider2D::CircleCollider2D ( float  friction,
float  bounciness,
float  radius = default_circle_collider_radius,
Point  offset = {0.0f, 0.0f},
bool  is_sensor = false,
bool  is_bullet = false 
)

◆ ~CircleCollider2D()

CircleCollider2D::~CircleCollider2D ( )
overridedefault

Member Function Documentation

◆ bounciness()

CircleCollider2D & CircleCollider2D::bounciness ( float  value)
overridevirtualnoexcept

Reimplemented from Collider2D.

◆ friction()

CircleCollider2D & CircleCollider2D::friction ( float  value)
overridevirtualnoexcept

Reimplemented from Collider2D.

◆ offset() [1/2]

Point CircleCollider2D::offset ( ) const
overridevirtualnoexcept

Reimplemented from Collider2D.

◆ offset() [2/2]

CircleCollider2D & CircleCollider2D::offset ( Point  value)
overridevirtualnoexcept

Reimplemented from Collider2D.

◆ radius() [1/2]

float CircleCollider2D::radius ( ) const
noexcept

◆ radius() [2/2]

CircleCollider2D & CircleCollider2D::radius ( float  value)
noexcept

◆ type_name()

std::string CircleCollider2D::type_name ( ) const
overridevirtual

Provides a consistent type name for the component.

Returns
A string representing the type name of the component. @CAUTION: All derived components must implement this method to ensure consistent serialization across different compilers and platforms.

Implements Component.

◆ update()

void CircleCollider2D::update ( float  dt)
overridevirtual

Implements Component.


The documentation for this class was generated from the following file: