ShitEngine 1.4.2
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
SpriteSheet.h
浏览该文件的文档.
1#pragma once
2
3#include "../Core/Core.h"
4#include "../Math.h"
5#include <vector>
6#include <cstddef>
7#include <algorithm>
8
9namespace Shit {
10
23class SHIT_API SpriteSheet final {
24public:
25 SpriteSheet(int rows, int cols, float frameWidth, float frameHeight,
26 float margin = 0.0f, float spacing = 0.0f);
27
28 ~SpriteSheet() = default;
29
30 SpriteSheet(const SpriteSheet&) = default;
31 SpriteSheet& operator=(const SpriteSheet&) = default;
32 SpriteSheet(SpriteSheet&&) noexcept = default;
33 SpriteSheet& operator=(SpriteSheet&&) noexcept = default;
34
35 Rect getFrameRect(int frameIndex) const;
36 Rect getFrameRect(int row, int col) const;
37
38 int getRows() const { return m_rows; }
39 int getCols() const { return m_cols; }
40 float getFrameWidth() const { return m_frameWidth; }
41 float getFrameHeight() const { return m_frameHeight; }
42 float getMargin() const { return m_margin; }
43 float getSpacing() const { return m_spacing; }
44 int getFrameCount() const { return m_rows * m_cols; }
45
46 void setRows(int rows) { m_rows = std::max(1, rows); }
47 void setCols(int cols) { m_cols = std::max(1, cols); }
48 void setFrameWidth(float width) { m_frameWidth = std::max(0.0f, width); }
49 void setFrameHeight(float height) { m_frameHeight = std::max(0.0f, height); }
50 void setMargin(float margin) { m_margin = std::max(0.0f, margin); }
51 void setSpacing(float spacing) { m_spacing = std::max(0.0f, spacing); }
52
53private:
54 int m_rows = 0;
55 int m_cols = 0;
56 float m_frameWidth = 0.0f;
57 float m_frameHeight = 0.0f;
58 float m_margin = 0.0f;
59 float m_spacing = 0.0f;
60};
61
62} // namespace Shit
#define SHIT_API
定义 Core.h:14
int getFrameCount() const
定义 SpriteSheet.h:44
float getSpacing() const
定义 SpriteSheet.h:43
int getCols() const
定义 SpriteSheet.h:39
void setSpacing(float spacing)
定义 SpriteSheet.h:51
void setMargin(float margin)
定义 SpriteSheet.h:50
void setRows(int rows)
定义 SpriteSheet.h:46
SpriteSheet(SpriteSheet &&) noexcept=default
void setFrameHeight(float height)
定义 SpriteSheet.h:49
Rect getFrameRect(int frameIndex) const
float getFrameHeight() const
定义 SpriteSheet.h:41
float getFrameWidth() const
定义 SpriteSheet.h:40
SpriteSheet & operator=(const SpriteSheet &)=default
void setCols(int cols)
定义 SpriteSheet.h:47
void setFrameWidth(float width)
定义 SpriteSheet.h:48
~SpriteSheet()=default
SpriteSheet(const SpriteSheet &)=default
float getMargin() const
定义 SpriteSheet.h:42
int getRows() const
定义 SpriteSheet.h:38
SpriteSheet(int rows, int cols, float frameWidth, float frameHeight, float margin=0.0f, float spacing=0.0f)
定义 AnimationClip.h:12
Rectangle struct (float precision), with SDL_FRect conversion
定义 Math.h:10