ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
Animation.h
浏览该文件的文档.
1#pragma once
2
3#include "../Core/Core.h"
4#include <SDL3/SDL_rect.h>
5#include <string>
6#include <vector>
7
8namespace Shit{
16 class SHIT_API Animation final {
17 public:
18 Animation(float duration = 0.1f, bool loop = true);
20
21 void addFrame(const SDL_FRect& frame);
22 void addFrames(const std::vector<SDL_FRect>& frames);
23
24 SDL_FRect getFrame(float elapsedTime) const;
25
26 // --- getter & setter ---
27 void setLoop(bool loop) { m_loop = loop; }
28 void setDuration(float duration) { m_duration = duration; }
29
30 bool isLooping() const { return m_loop; }
31 float getDuration() const { return m_duration; }
32 int getFrameCount() const { return static_cast<int>(m_frames.size()); }
33
34 private:
35 std::vector<SDL_FRect> m_frames;
36 float m_duration;
37 bool m_loop = true;
38 };
39}
#define SHIT_API
定义 Core.h:12
int getFrameCount() const
定义 Animation.h:32
float getDuration() const
定义 Animation.h:31
SDL_FRect getFrame(float elapsedTime) const
根据已播放时间返回当前帧的源矩形
Animation(float duration=0.1f, bool loop=true)
bool isLooping() const
定义 Animation.h:30
void setDuration(float duration)
定义 Animation.h:28
void setLoop(bool loop)
定义 Animation.h:27
void addFrames(const std::vector< SDL_FRect > &frames)
批量添加帧
void addFrame(const SDL_FRect &frame)
添加单帧
定义 AudioPlayer.h:9