载入中...
搜索中...
未找到
SpineAnim.h
浏览该文件的文档.
1#pragma once
2
3#include <string>
4#include <vector>
6
7namespace eve::graphics {
8struct DrawItem2D;
9class Texture;
10} // namespace eve::graphics
11
12#include <string>
13#include <vector>
14
15namespace eve::graphics {
16class Graphics;
17}
18
19namespace eve::animation {
20
21class Animation;
22class SpineAtlas;
23class SpineSkeleton;
24
32class SpineAnim {
33public:
34 explicit SpineAnim(SpineSkeleton *skeleton);
35 ~SpineAnim();
36
37 SpineAnim(const SpineAnim &) = delete;
38 SpineAnim &operator=(const SpineAnim &) = delete;
39
40 SpineSkeleton *getSkeleton() const { return skeleton_; }
41
42 void setAtlas(SpineAtlas *atlas);
43 SpineAtlas *getAtlas() const { return atlas_; }
44
46 void setPageTexture(int pageIndex, graphics::Texture *texture);
47 void setPageTextureByName(const std::string &pageName, graphics::Texture *texture);
48 graphics::Texture *getPageTexture(int pageIndex) const;
49
50 bool play(const std::string &animationName);
51 void stop();
52 void pause();
53 void resume();
54
55 void setSpeed(float speed);
56 float getSpeed() const { return speed_; }
57 void setTime(float seconds);
58 float getTime() const { return time_; }
59 void setLoop(bool loop) { loop_ = loop; }
60 bool getLoop() const { return loop_; }
61
63 void setFlipY(bool flip) { flipY_ = flip; }
64 bool getFlipY() const { return flipY_; }
65
66 void setPosition(float x, float y);
67 float getX() const { return x_; }
68 float getY() const { return y_; }
69 void setScale(float sx, float sy);
70 float getScaleX() const { return scaleX_; }
71 float getScaleY() const { return scaleY_; }
72 void setLayer(int layer) { layer_ = layer; }
73 int getLayer() const { return layer_; }
74 void setColor(float r, float g, float b, float a = 1.f);
75
76 bool isPlaying() const { return playing_ && !paused_; }
77 bool isPaused() const { return paused_; }
78 bool isFinished() const { return finished_; }
79 std::string getAnimation() const { return animName_; }
80 float getAnimationDuration() const;
81
83 void apply();
84
85 bool update(float dt);
86
88 void collectDrawItems(std::vector<graphics::DrawItem2D> &out);
90 void draw(graphics::Graphics *gfx);
91
96 int getDrawSlotCount() const;
97 float getDrawSlotX(int index) const;
98 float getDrawSlotY(int index) const;
99 float getDrawSlotWidth(int index) const;
100 float getDrawSlotHeight(int index) const;
101 float getDrawSlotRotation(int index) const;
102 int getDrawSlotPage(int index) const;
103 std::string getDrawSlotRegion(int index) const;
104
105private:
106 friend class Animation;
107
108 struct DrawSlot {
109 float x = 0.f, y = 0.f;
110 float w = 0.f, h = 0.f;
111 float rotation = 0.f;
112 int page = 0;
113 int region = -1;
114 int order = 0; // slot draw order (back-to-front)
115 bool rotated = false; // atlas region packed rotated (90°)
116 std::string regionName;
117 float u0 = 0.f, v0 = 0.f, u1 = 1.f, v1 = 1.f;
118 };
119
120 void setOwner(Animation *owner) { owner_ = owner; }
121 Animation *owner() const { return owner_; }
122
123 void rebuildDrawSlots();
124 void checkDrawSlot(int index) const;
125
126 static float sampleFloat(const std::vector<SpineSkeletonData::FloatKey> &keys, float time,
127 float fallback);
128 static void sampleTranslate(const std::vector<SpineSkeletonData::TranslateKey> &keys,
129 float time, float &x, float &y);
130 static void sampleScale(const std::vector<SpineSkeletonData::ScaleKey> &keys, float time,
131 float &x, float &y);
132 static std::string sampleAttachment(const std::vector<SpineSkeletonData::AttachmentKey> &keys,
133 float time, const std::string &fallback);
134
135 Animation *owner_ = nullptr;
136 SpineSkeleton *skeleton_ = nullptr;
137 SpineAtlas *atlas_ = nullptr;
138 std::vector<graphics::Texture *> pageTextures_;
139 int animIndex_ = -1;
140 std::string animName_;
141 float speed_ = 1.f;
142 float time_ = 0.f;
143 bool loop_ = true;
144 bool playing_ = false;
145 bool paused_ = false;
146 bool finished_ = false;
147 bool flipY_ = true;
148 float x_ = 0.f, y_ = 0.f;
149 float scaleX_ = 1.f, scaleY_ = 1.f;
150 int layer_ = 0;
151 float r_ = 1.f, g_ = 1.f, b_ = 1.f, a_ = 1.f;
152 std::vector<DrawSlot> drawSlots_;
153};
154
155} // namespace eve::animation
int y
Definition Grass.cpp:135
int x
Definition Grass.cpp:135
int h
int w
uint32_t a
uint32_t b
TileLayer * layer
Animation module — tween factory + 2D sprite-sheet / Spine + 3D skeletal playback (player / state mac...
Definition Animation.h:53
Spine animation player + 2D draw collector (region attachments).
Definition SpineAnim.h:32
void apply()
Apply current animation time to skeleton and update world transforms.
void setPageTexture(int pageIndex, graphics::Texture *texture)
Bind a GPU texture to an atlas page (by index or page image name).
Definition SpineAnim.cpp:35
SpineAtlas * getAtlas() const
Definition SpineAnim.h:43
graphics::Texture * getPageTexture(int pageIndex) const
Definition SpineAnim.cpp:55
float getDrawSlotHeight(int index) const
void setSpeed(float speed)
Definition SpineAnim.cpp:91
void setPageTextureByName(const std::string &pageName, graphics::Texture *texture)
Definition SpineAnim.cpp:44
float getDrawSlotX(int index) const
void setAtlas(SpineAtlas *atlas)
Definition SpineAnim.cpp:29
void setScale(float sx, float sy)
float getScaleX() const
Definition SpineAnim.h:70
SpineSkeleton * getSkeleton() const
Definition SpineAnim.h:40
int getDrawSlotCount() const
Query posed draw slots without textures (for unit tests). Returns number of visible region attachment...
void setLayer(int layer)
Definition SpineAnim.h:72
float getAnimationDuration() const
float getDrawSlotRotation(int index) const
float getDrawSlotY(int index) const
void setLoop(bool loop)
Definition SpineAnim.h:59
void collectDrawItems(std::vector< graphics::DrawItem2D > &out)
Append region attachment quads into the shared 2D draw queue.
bool isFinished() const
Definition SpineAnim.h:78
float getSpeed() const
Definition SpineAnim.h:56
void setPosition(float x, float y)
bool play(const std::string &animationName)
Definition SpineAnim.cpp:60
SpineAnim(const SpineAnim &)=delete
float getDrawSlotWidth(int index) const
std::string getDrawSlotRegion(int index) const
void setColor(float r, float g, float b, float a=1.f)
float getTime() const
Definition SpineAnim.h:58
void setFlipY(bool flip)
When true (default), Spine Y-up is flipped for screen Y-down draw items.
Definition SpineAnim.h:63
float getScaleY() const
Definition SpineAnim.h:71
std::string getAnimation() const
Definition SpineAnim.h:79
void setTime(float seconds)
Definition SpineAnim.cpp:96
void draw(graphics::Graphics *gfx)
Draw the current pose into an existing frame without clearing or presenting it.
int getDrawSlotPage(int index) const
SpineAnim & operator=(const SpineAnim &)=delete
Esoteric Spine .atlas text parser (region rectangles + page metadata). Does not load image pixels — b...
Definition SpineAtlas.h:14
Runtime Spine skeleton pose (local + world bone transforms, slot attachments). Script type: SpineSkel...
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:17
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition AnimTrail.h:6