ShitEngine
基于 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 Vector2getSize () 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
Componentoperator= (const Component &)=delete
 Component (Component &&)=delete
Componentoperator= (Component &&)=delete
GameObjectgetOwner () const
bool isRegistered () const

额外继承的成员函数

Protected 成员函数 继承自 Component
void setRegistered (bool registered)
Protected 属性 继承自 Component
GameObjectm_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() [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 .

◆ 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}


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