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