|
ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
|
盒子碰撞体组件 更多...
#include <BoxCollider2D.h>
Public 成员函数 | |
| BoxCollider2D () | |
| BoxCollider2D (const Vector2 &size) | |
| ~BoxCollider2D () override | |
| void | onAttach () override |
| void | onDetach () override |
| void | onDestroy () override |
| void | ensureShape () |
| 内部:若同物体存在有效刚体则创建碰撞形状(幂等)。刚体后置挂载时由物理系统补调。 | |
| void | setSize (const Vector2 &size) |
| 像素尺寸(宽/高)默认 {32, 32} | |
| const Vector2 & | getSize () 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* box = go->addComponent<Shit::BoxCollider2D>(); box->setSize({ 64, 64 }); // 像素尺寸 box->setDensity(1.0f); box->setFriction(0.3f);
| BoxCollider2D | ( | ) |
|
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 setRestitution | ( | float | restitution | ) |
弹性系数,默认 0.0f
| void setSize | ( | const Vector2 & | size | ) |
像素尺寸(宽/高)默认 {32, 32}