ShitEngine
1.4.2
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
Toggle main menu visibility
载入中...
搜索中...
未找到
Behavior.h
浏览该文件的文档.
1
#pragma once
2
#include "
Component.h
"
3
4
namespace
Shit
{
5
class
GameObject
;
6
22
class
SHIT_API
SHIT_REFLECT
(BlackList)
Behavior
:
public
Component
{
23
friend
class
GameObject
;
24
SHIT_REFLECT_BODY
(
Behavior
)
25
public
:
26
Behavior
() =
default
;
27
~Behavior
()
override
=
default
;
28
29
// --- 生命周期 ---
30
void
onCreate
()
override
;
31
void
onAttach
()
override
;
32
virtual
void
onStart
();
33
virtual
void
onFixedUpdate
(
float
fixedDt);
34
virtual
void
onUpdate
();
35
36
// --- 碰撞回调(由 PhysicsSystem2D 驱动;仅 onStart 已执行的行为可收到) ---
37
virtual
void
onCollisionEnter
(
GameObject
* other);
38
virtual
void
onCollisionStay
(
GameObject
* other);
39
virtual
void
onCollisionExit
(
GameObject
* other);
40
41
void
onDetach
()
override
;
42
void
onDestroy
()
override
;
43
44
bool
isStarted
()
const
{
return
m_isStarted
; }
45
void
setStarted
(
bool
isStarted
) {
m_isStarted
=
isStarted
; }
46
47
protected
:
48
SHIT_META
(({.displayName =
"Started"
, .tooltip =
"onStart 是否已执行过"
, .readOnly =
true
}))
49
bool
m_isStarted
=
false
;
50
};
51
}
Component.h
SHIT_API
#define SHIT_API
定义
Core.h:14
SHIT_REFLECT_BODY
#define SHIT_REFLECT_BODY(Type)
定义
Macros.h:89
SHIT_REFLECT
#define SHIT_REFLECT(Mode)
定义
Macros.h:86
SHIT_META
#define SHIT_META(...)
定义
Macros.h:95
Shit::Behavior::GameObject
friend class GameObject
定义
Behavior.h:23
Shit::Behavior::m_isStarted
bool m_isStarted
定义
Behavior.h:49
Shit::Behavior::onCollisionEnter
virtual void onCollisionEnter(GameObject *other)
与 other 开始接触(每对象对一次)
Shit::Behavior::onCollisionStay
virtual void onCollisionStay(GameObject *other)
与 other 持续接触(每帧一次)
Shit::Behavior::Behavior
Behavior()=default
Shit::Behavior::~Behavior
~Behavior() override=default
Shit::Behavior::onStart
virtual void onStart()
首次 update 前执行一次
Shit::Behavior::setStarted
void setStarted(bool isStarted)
定义
Behavior.h:45
Shit::Behavior::onFixedUpdate
virtual void onFixedUpdate(float fixedDt)
固定步长执行(与物理同拍;Scene 固定步循环驱动)
Shit::Behavior::isStarted
bool isStarted() const
onStart 是否已执行过
定义
Behavior.h:44
Shit::Behavior::onUpdate
virtual void onUpdate()
每帧执行
Shit::Behavior::onCreate
void onCreate() override
Shit::Behavior::onAttach
void onAttach() override
Shit::Behavior::onDetach
void onDetach() override
Shit::Behavior::onDestroy
void onDestroy() override
Shit::Behavior::onCollisionExit
virtual void onCollisionExit(GameObject *other)
与 other 结束接触
Shit::Component::Component
Component()
Shit::GameObject
游戏物体类
定义
GameObject.h:23
Shit
定义
AnimationClip.h:12
include
ShitEngine
Component
Behavior.h
制作者
1.17.0