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
8namespace Shit {
9
22class SHIT_API SpriteSheet final {
23public:
33 SpriteSheet(int rows, int cols, float frameWidth, float frameHeight,
34 float margin = 0.0f, float spacing = 0.0f);
35
36 ~SpriteSheet() = default;
37
38 SpriteSheet(const SpriteSheet&) = default;
39 SpriteSheet& operator=(const SpriteSheet&) = default;
40 SpriteSheet(SpriteSheet&&) noexcept = default;
41 SpriteSheet& operator=(SpriteSheet&&) noexcept = default;
42
44 SDL_FRect getFrameRect(int frameIndex) const;
45
47 SDL_FRect getFrameRect(int row, int col) const;
48
49 int getRows() const { return m_rows; }
50 int getCols() const { return m_cols; }
51 float getFrameWidth() const { return m_frameWidth; }
52 float getFrameHeight() const { return m_frameHeight; }
53 float getMargin() const { return m_margin; }
54 float getSpacing() const { return m_spacing; }
55 int getFrameCount() const { return m_rows * m_cols; }
56
57 void setRows(int rows) { m_rows = rows; }
58 void setCols(int cols) { m_cols = cols; }
59 void setFrameWidth(float width) { m_frameWidth = width; }
60 void setFrameHeight(float height) { m_frameHeight = height; }
61 void setMargin(float margin) { m_margin = margin; }
62 void setSpacing(float spacing) { m_spacing = spacing; }
63
64private:
65 int m_rows = 0;
66 int m_cols = 0;
67 float m_frameWidth = 0.0f;
68 float m_frameHeight = 0.0f;
69 float m_margin = 0.0f;
70 float m_spacing = 0.0f;
71};
72
73} // namespace Shit
#define SHIT_API
定义 Core.h:12
int getFrameCount() const
定义 SpriteSheet.h:55
float getSpacing() const
定义 SpriteSheet.h:54
int getCols() const
定义 SpriteSheet.h:50
void setSpacing(float spacing)
定义 SpriteSheet.h:62
void setMargin(float margin)
定义 SpriteSheet.h:61
void setRows(int rows)
定义 SpriteSheet.h:57
SpriteSheet(SpriteSheet &&) noexcept=default
void setFrameHeight(float height)
定义 SpriteSheet.h:60
float getFrameHeight() const
定义 SpriteSheet.h:52
float getFrameWidth() const
定义 SpriteSheet.h:51
SpriteSheet & operator=(const SpriteSheet &)=default
void setCols(int cols)
定义 SpriteSheet.h:58
SDL_FRect getFrameRect(int frameIndex) const
全局帧索引(0..rows*cols-1)对应的源矩形
void setFrameWidth(float width)
定义 SpriteSheet.h:59
~SpriteSheet()=default
SpriteSheet(const SpriteSheet &)=default
float getMargin() const
定义 SpriteSheet.h:53
int getRows() const
定义 SpriteSheet.h:49
SpriteSheet(int rows, int cols, float frameWidth, float frameHeight, float margin=0.0f, float spacing=0.0f)
构造网格切割参数
定义 AudioPlayer.h:9