ShitEngine 1.4.2
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
Sprite.h
浏览该文件的文档.
1#pragma once
2#include "../Core/Core.h"
3#include "../Math.h"
4#include <string>
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<Rect>& 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<Rect>& 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<Rect>& 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<Rect> m_sourceRect;
35 bool m_isFlipped = false;
36};
37
38} // namespace Shit
#define SHIT_API
定义 Core.h:14
void setSourceRect(const std::optional< Rect > &rect)
定义 Sprite.h:26
Sprite(const std::string &texturePath, const std::optional< Rect > &sourceRect=std::nullopt, bool flipped=false)
定义 Sprite.h:17
void setTexturePath(const std::string &texturePath)
定义 Sprite.h:25
const std::string & getTexturePath() const
定义 Sprite.h:21
void setFlipped(bool flipped)
定义 Sprite.h:27
void setFrame(const SpriteSheet &sheet, int frameIndex)
从 SpriteSheet 中取第 frameIndex 帧作为源矩形
const std::optional< Rect > & getSourceRect() const
定义 Sprite.h:22
bool isFlipped() const
定义 Sprite.h:23
Sprite sheet grid cutter
定义 SpriteSheet.h:23
定义 AnimationClip.h:12