ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
Sprite.h
浏览该文件的文档.
1#pragma once
2#include "../Core/Core.h"
3#include <string>
4#include <SDL3/SDL_rect.h>
5#include <optional>
6
7namespace Shit {
8
9class SpriteSheet;
10
14class SHIT_API Sprite final {
15public:
17 Sprite(const std::string& texturePath, const std::optional<SDL_FRect>& sourceRect = std::nullopt, bool flipped = false)
18 : m_texturePath(texturePath), m_sourceRect(sourceRect), m_isFlipped(flipped) {}
19
20 // --- getter & setter ---
21 const std::string& getTexturePath() const { return m_texturePath; }
22 const std::optional<SDL_FRect>& getSourceRect() const { return m_sourceRect; }
23 bool isFlipped() const { return m_isFlipped; }
24
25 void setTexturePath(const std::string& texturePath) { m_texturePath = texturePath; }
26 void setSourceRect(const std::optional<SDL_FRect>& rect) { m_sourceRect = rect; }
27 void setFlipped(bool flipped) { m_isFlipped = flipped; }
28
30 void setFrame(const SpriteSheet& sheet, int frameIndex);
31
32private:
33 std::string m_texturePath;
34 std::optional<SDL_FRect> m_sourceRect;
35 bool m_isFlipped = false;
36};
37
38} // namespace Shit
#define SHIT_API
定义 Core.h:12
void setTexturePath(const std::string &texturePath)
定义 Sprite.h:25
Sprite(const std::string &texturePath, const std::optional< SDL_FRect > &sourceRect=std::nullopt, bool flipped=false)
定义 Sprite.h:17
const std::string & getTexturePath() const
定义 Sprite.h:21
const std::optional< SDL_FRect > & getSourceRect() const
定义 Sprite.h:22
void setFlipped(bool flipped)
定义 Sprite.h:27
void setFrame(const SpriteSheet &sheet, int frameIndex)
从 SpriteSheet 中取第 frameIndex 帧作为源矩形
void setSourceRect(const std::optional< SDL_FRect > &rect)
定义 Sprite.h:26
bool isFlipped() const
定义 Sprite.h:23
精灵图集(sprite-sheet)网格切割器
定义 SpriteSheet.h:22
定义 AudioPlayer.h:9