ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
SpriteSheet.h
浏览该文件的文档.
1#pragma once
2
3#include "../Core/Core.h"
4#include <SDL3/SDL_rect.h>
5#include <vector>
6#include <cstddef>
7#include <algorithm>
8
9namespace Shit {
10
23class SHIT_API SpriteSheet final {
24public:
34 SpriteSheet(int rows, int cols, float frameWidth, float frameHeight,
35 float margin = 0.0f, float spacing = 0.0f);
36
37 ~SpriteSheet() = default;
38
39 SpriteSheet(const SpriteSheet&) = default;
40 SpriteSheet& operator=(const SpriteSheet&) = default;
41 SpriteSheet(SpriteSheet&&) noexcept = default;
42 SpriteSheet& operator=(SpriteSheet&&) noexcept = default;
43
45 SDL_FRect getFrameRect(int frameIndex) const;
46
48 SDL_FRect getFrameRect(int row, int col) const;
49
50 int getRows() const { return m_rows; }
51 int getCols() const { return m_cols; }
52 float getFrameWidth() const { return m_frameWidth; }
53 float getFrameHeight() const { return m_frameHeight; }
54 float getMargin() const { return m_margin; }
55 float getSpacing() const { return m_spacing; }
56 int getFrameCount() const { return m_rows * m_cols; }
57
58 void setRows(int rows) { m_rows = std::max(1, rows); }
59 void setCols(int cols) { m_cols = std::max(1, cols); }
60 void setFrameWidth(float width) { m_frameWidth = std::max(0.0f, width); }
61 void setFrameHeight(float height) { m_frameHeight = std::max(0.0f, height); }
62 void setMargin(float margin) { m_margin = std::max(0.0f, margin); }
63 void setSpacing(float spacing) { m_spacing = std::max(0.0f, spacing); }
64
65private:
66 int m_rows = 0;
67 int m_cols = 0;
68 float m_frameWidth = 0.0f;
69 float m_frameHeight = 0.0f;
70 float m_margin = 0.0f;
71 float m_spacing = 0.0f;
72};
73
74} // namespace Shit
#define SHIT_API
定义 Core.h:14
int getFrameCount() const
定义 SpriteSheet.h:56
float getSpacing() const
定义 SpriteSheet.h:55
int getCols() const
定义 SpriteSheet.h:51
void setSpacing(float spacing)
定义 SpriteSheet.h:63
void setMargin(float margin)
定义 SpriteSheet.h:62
void setRows(int rows)
定义 SpriteSheet.h:58
SpriteSheet(SpriteSheet &&) noexcept=default
void setFrameHeight(float height)
定义 SpriteSheet.h:61
float getFrameHeight() const
定义 SpriteSheet.h:53
float getFrameWidth() const
定义 SpriteSheet.h:52
SpriteSheet & operator=(const SpriteSheet &)=default
void setCols(int cols)
定义 SpriteSheet.h:59
SDL_FRect getFrameRect(int frameIndex) const
全局帧索引(0..rows*cols-1)对应的源矩形
void setFrameWidth(float width)
定义 SpriteSheet.h:60
~SpriteSheet()=default
SpriteSheet(const SpriteSheet &)=default
float getMargin() const
定义 SpriteSheet.h:54
int getRows() const
定义 SpriteSheet.h:50
SpriteSheet(int rows, int cols, float frameWidth, float frameHeight, float margin=0.0f, float spacing=0.0f)
构造网格切割参数
定义 AudioPlayer.h:10