|
ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
|
圆形碰撞体组件 更多...
#include <CircleCollider2D.h>
Public 成员函数 | |
| CircleCollider2D () | |
| CircleCollider2D (float radius) | |
| ~CircleCollider2D () override | |
| void | onAttach () override |
| void | onDetach () override |
| void | onDestroy () override |
| void | ensureShape () |
| 内部:若同物体存在有效刚体则创建碰撞形状(幂等)。刚体后置挂载时由物理系统补调。 | |
| void | setRadius (float radius) |
| 像素半径,默认 16.0f | |
| float | getRadius () const |
| void | setDensity (float density) |
| 密度,默认 1.0f | |
| float | getDensity () const |
| void | setFriction (float friction) |
| 摩擦系数,默认 0.3f | |
| float | getFriction () const |
| void | setRestitution (float restitution) |
| 弹性系数,默认 0.0f | |
| float | getRestitution () const |
| Public 成员函数 继承自 Component | |
| Component () | |
| virtual | ~Component ()=default |
| virtual void | onCreate () |
| virtual void | onAfterDeserialize () |
| 反序列化完成后回调(Prefab::apply 逐组件调用一次,字段已写入)。 用于重建"直写字段绕过了 setter、无法自动触发的引擎状态"(如精灵纹理加载)。 | |
| Component (const Component &)=delete | |
| Component & | operator= (const Component &)=delete |
| Component (Component &&)=delete | |
| Component & | operator= (Component &&)=delete |
| GameObject * | getOwner () const |
| bool | isRegistered () const |
额外继承的成员函数 | |
| Protected 成员函数 继承自 Component | |
| void | setRegistered (bool registered) |
| Protected 属性 继承自 Component | |
| GameObject * | m_owner = nullptr |
| bool | m_isRegistered = false |
圆形碰撞体组件
在同 GameObject 上添加一个圆形碰撞形状,附着于其 RigidBody2D。 挂载顺序不敏感:若碰撞体先于 RigidBody2D 挂载,刚体创建后会补建碰撞形状 (由 PhysicsSystem2D 在 createRigidBody 时调用 ensureShape)。
使用方式: auto* ball = scene->createGameObject("Ball"); ball->addComponent<Shit::TransformComponent>()->setPosition({400, 100}); ball->addComponent<Shit::RigidBody2D>()->setBodyType(Shit::RigidBody2D::Type::Dynamic); auto* collider = ball->addComponent<Shit::CircleCollider2D>(); collider->setRadius(24);
| CircleCollider2D | ( | ) |
|
explicit |
|
override |
| void ensureShape | ( | ) |
内部:若同物体存在有效刚体则创建碰撞形状(幂等)。刚体后置挂载时由物理系统补调。
|
inline |
|
inline |
|
inline |
|
inline |
|
overridevirtual |
重载 Component .
|
overridevirtual |
重载 Component .
|
overridevirtual |
重载 Component .
| void setDensity | ( | float | density | ) |
密度,默认 1.0f
| void setFriction | ( | float | friction | ) |
摩擦系数,默认 0.3f
| void setRadius | ( | float | radius | ) |
像素半径,默认 16.0f
| void setRestitution | ( | float | restitution | ) |
弹性系数,默认 0.0f