ShitEngine 1.4.2
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
BoxCollider2D类 参考

盒子碰撞体组件 更多...

#include <BoxCollider2D.h>

类 BoxCollider2D 继承关系图:
Component

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 onFieldChanged (const std::string &fieldName) override
 检查器直写反射字段后回调:把尺寸改动同步到已创建的 Box2D 形状
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
uint64_t getUuid () const
 组件持久 ID(随 .scene 序列化,是 ComponentRef<T> 引用字段的寻址依据)
void setUuid (uint64_t uuid)
 直接设置组件 ID(仅引擎反序列化/索引维护使用;正常流程由构造函数随机分配)

额外继承的成员函数

Protected 成员函数 继承自 Component
void setRegistered (bool registered)
Protected 属性 继承自 Component
GameObject * m_owner = nullptr
bool m_isRegistered = false
uint64_t m_uuid = 0
 持久 ID(构造时随机分配;0 仅在序列化前尚未赋值时短暂存在)

详细描述

盒子碰撞体组件

在同 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() [1/2]

BoxCollider2D ( )

◆ BoxCollider2D() [2/2]

BoxCollider2D ( const Vector2 & size)
explicit

◆ ~BoxCollider2D()

~BoxCollider2D ( )
override

成员函数说明

◆ ensureShape()

void ensureShape ( )

内部:若同物体存在有效刚体则创建碰撞形状(幂等)。刚体后置挂载时由物理系统补调。

◆ getDensity()

float getDensity ( ) const
inline

◆ getFriction()

float getFriction ( ) const
inline

◆ getRestitution()

float getRestitution ( ) const
inline

◆ getSize()

const Vector2 & getSize ( ) const
inline

◆ onAttach()

void onAttach ( )
overridevirtual

重载 Component .

◆ onDestroy()

void onDestroy ( )
overridevirtual

重载 Component .

◆ onDetach()

void onDetach ( )
overridevirtual

重载 Component .

◆ onFieldChanged()

void onFieldChanged ( const std::string & fieldName)
overridevirtual

检查器直写反射字段后回调:把尺寸改动同步到已创建的 Box2D 形状

重载 Component .

◆ setDensity()

void setDensity ( float density)

密度,默认 1.0f

◆ setFriction()

void setFriction ( float friction)

摩擦系数,默认 0.3f

◆ setRestitution()

void setRestitution ( float restitution)

弹性系数,默认 0.0f

◆ setSize()

void setSize ( const Vector2 & size)

像素尺寸(宽/高)默认 {32, 32}


该类的文档由以下文件生成: