ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
Toggle main menu visibility
载入中...
搜索中...
未找到
AnimationComponent.h
浏览该文件的文档.
1
#pragma once
2
3
#include "
Behavior.h
"
4
#include "
../Core/Core.h
"
5
#include "
../Render/SpriteSheet.h
"
6
7
#include <string>
8
#include <unordered_map>
9
#include <memory>
10
#include <vector>
11
12
namespace
Shit
13
{
14
class
Animation
;
15
31
class
SHIT_API
SHIT_REFLECT
(BlackList)
AnimationComponent
:
public
Behavior
{
32
SHIT_REFLECT_BODY
(
AnimationComponent
)
33
public
:
34
AnimationComponent
();
35
~AnimationComponent
()
override
;
36
37
// --- 生命周期 ---
38
void
onAttach
()
override
;
39
void
onStart
()
override
;
40
void
onUpdate
()
override
;
41
void
onDestroy
()
override
;
42
43
// --- 动画管理 ---
44
void
addAnimation
(
const
std::string& name, std::unique_ptr<Animation> animation);
45
46
void
play
(
const
std::string& name);
47
void
stop
();
48
void
pause
();
49
void
resume
();
50
63
void
play
(
const
std::string& name,
const
SpriteSheet
& sheet,
64
const
std::vector<int>& frames,
float
duration = 0.1f,
bool
loop =
true
);
65
66
// --- 查询 ---
67
bool
isPlaying
()
const
{
return
m_isPlaying; }
68
bool
isPaused
()
const
{
return
m_isPaused; }
69
const
std::string&
getCurrentAnimationName
()
const
{
return
m_currentAnimationName; }
70
71
private
:
72
// 把当前帧源矩形回写到 SpriteRenderer(若存在且纹理一致)
73
void
applyCurrentFrame();
74
75
SHIT_META
(Disable)
76
std::unordered_map<std::string, std::unique_ptr<Animation>> m_animations;
77
SHIT_META
(Disable)
78
Animation
* m_currentAnimation =
nullptr
;
79
SHIT_META
(({.displayName =
"Current Animation"
, .readOnly =
true
}))
80
std::string m_currentAnimationName;
81
SHIT_META
(({.displayName =
"Current Time"
, .readOnly =
true
}))
82
float
m_currentTime = 0.0f;
83
84
SHIT_META
(({.displayName =
"Playing"
, .readOnly =
true
}))
85
bool
m_isPlaying =
false
;
86
SHIT_META
(({.displayName =
"Paused"
, .readOnly =
true
}))
87
bool
m_isPaused =
false
;
88
};
89
}
Behavior.h
Core.h
SHIT_API
#define SHIT_API
定义
Core.h:14
SHIT_REFLECT_BODY
#define SHIT_REFLECT_BODY(Type)
定义
Macros.h:62
SHIT_REFLECT
#define SHIT_REFLECT(Mode)
定义
Macros.h:59
SHIT_META
#define SHIT_META(...)
定义
Macros.h:68
SpriteSheet.h
Shit::AnimationComponent::onStart
void onStart() override
首次 update 前执行一次
Shit::AnimationComponent::getCurrentAnimationName
const std::string & getCurrentAnimationName() const
定义
AnimationComponent.h:69
Shit::AnimationComponent::play
void play(const std::string &name)
Shit::AnimationComponent::isPlaying
bool isPlaying() const
定义
AnimationComponent.h:67
Shit::AnimationComponent::resume
void resume()
Shit::AnimationComponent::isPaused
bool isPaused() const
定义
AnimationComponent.h:68
Shit::AnimationComponent::pause
void pause()
Shit::AnimationComponent::stop
void stop()
Shit::AnimationComponent::~AnimationComponent
~AnimationComponent() override
Shit::AnimationComponent::onAttach
void onAttach() override
Shit::AnimationComponent::AnimationComponent
AnimationComponent()
Shit::AnimationComponent::play
void play(const std::string &name, const SpriteSheet &sheet, const std::vector< int > &frames, float duration=0.1f, bool loop=true)
用数字帧索引直接设置并播放一段动画
Shit::AnimationComponent::onUpdate
void onUpdate() override
每帧执行
Shit::AnimationComponent::onDestroy
void onDestroy() override
Shit::AnimationComponent::addAnimation
void addAnimation(const std::string &name, std::unique_ptr< Animation > animation)
Shit::Animation
逐帧动画数据
定义
Animation.h:16
Shit::Behavior::Behavior
Behavior()=default
Shit::SpriteSheet
精灵图集(sprite-sheet)网格切割器
定义
SpriteSheet.h:23
Shit
定义
AudioPlayer.h:10
include
ShitEngine
Component
AnimationComponent.h
制作者
1.17.0