载入中...
搜索中...
未找到
SpriteSheet.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include <string>
6#include <unordered_map>
7#include <vector>
8
9namespace eve::graphics {
10class Quad;
11class Texture;
12}
13
14namespace eve::animation {
15
24public:
26 SpriteSheet() = default;
28 ~SpriteSheet() = default;
29
30 SpriteSheet(const SpriteSheet &) = delete;
31 SpriteSheet &operator=(const SpriteSheet &) = delete;
32
34 int addFrame(const std::string &name, int x, int y, int w, int h);
36 int addFrameTrimmed(const std::string &name, int x, int y, int w, int h,
37 int sourceW, int sourceH, int offsetX, int offsetY);
38
44 int setGrid(int columns, int rows, int frameW, int frameH, int margin = 0, int spacing = 0,
45 int originX = 0, int originY = 0);
46
48 void clear();
49
51 void setTexture(graphics::Texture *texture) { texture_ = texture; }
53 graphics::Texture *getTexture() const { return texture_; }
54
56 int getFrameCount() const { return static_cast<int>(frames_.size()); }
58 int findFrame(const std::string &name) const;
60 std::string getFrameName(int index) const;
62 int getFrameX(int index) const;
64 int getFrameY(int index) const;
66 int getFrameWidth(int index) const;
68 int getFrameHeight(int index) const;
70 int getFrameSourceWidth(int index) const;
72 int getFrameSourceHeight(int index) const;
74 int getFrameOffsetX(int index) const;
76 int getFrameOffsetY(int index) const;
77
79 void applyToQuad(graphics::Quad *quad, int frameIndex) const;
81 SpriteSheet *clone() const;
82
83private:
84 struct Frame {
85 std::string name;
86 int x = 0, y = 0, w = 0, h = 0;
87 int sourceW = 0, sourceH = 0, offsetX = 0, offsetY = 0;
88 };
89
90 void checkIndex(int index) const;
91 std::vector<Frame> frames_;
92 std::unordered_map<std::string, int> byName_;
93 graphics::Texture *texture_ = nullptr;
94};
95
96} // namespace eve::animation
float w
Definition AnimClip.cpp:738
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
#define EVENGINE_API_WORLD
Definition Export.h:109
int rows
int h
std::string name
int spacing
int columns
float offsetX
float offsetY
int margin
uint32_t index
Sprite-sheet / texture-atlas frame table (pixel rects).
Definition SpriteSheet.h:23
SpriteSheet()=default
Sprite sheet.
int getFrameCount() const
Returns the frame count.
Definition SpriteSheet.h:56
graphics::Texture * getTexture() const
Return the optional atlas texture without transferring ownership.
Definition SpriteSheet.h:53
SpriteSheet(const SpriteSheet &)=delete
void setTexture(graphics::Texture *texture)
Optional atlas texture produced by a sequence loader or assigned by the user.
Definition SpriteSheet.h:51
SpriteSheet & operator=(const SpriteSheet &)=delete
~SpriteSheet()=default
Sprite sheet.
Pixel-space sub-rectangle of a Texture (atlas cell / sprite frame). UV conversion uses the texture's ...
Definition Quad.h:11
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:18
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25