载入中...
搜索中...
未找到
SpriteAnim.h
浏览该文件的文档.
1#pragma once
2
3#include "common/Time.h"
4
5#include <string>
6#include <vector>
7
8namespace eve::graphics {
9class Quad;
10class Renderable2D;
11}
12
13namespace eve::animation {
14
15class Animation;
16class SpriteClip;
17class SpriteSheet;
18
27public:
32
33 SpriteAnim(const SpriteAnim &) = delete;
34 SpriteAnim &operator=(const SpriteAnim &) = delete;
35
37 void setSheet(SpriteSheet *sheet);
39 SpriteSheet *getSheet() const { return sheet_; }
40
42 void play(SpriteClip *clip);
44 void playReverse(SpriteClip *clip);
46 void stop();
48 void pause();
50 void resume();
51
53 void setSpeed(float speed);
55 float getSpeed() const { return speed_; }
57 void addSpeedCurveKey(float seconds, float multiplier);
59 void clearSpeedCurve();
61 void resetSpeedCurve();
63 void setSpeedCurveLoop(bool loop) { speedCurveLoop_ = loop; }
65 void setSpeedCurveInterpolation(const std::string &mode);
67 float getSpeedCurveValue() const;
69 void setFrame(int clipFrame);
71 void step(int frames);
73 void playOnce(SpriteClip *clip);
75 void queue(SpriteClip *clip);
77 std::string consumeEvent();
79 void setTime(float seconds);
81 float getTime() const { return time_; }
83 void setLoop(bool loop);
85 bool getLoop() const;
86
88 bool isPlaying() const { return playing_ && !paused_; }
90 bool isPaused() const { return paused_; }
92 bool isFinished() const { return finished_; }
94 int getLoopCount() const { return loopCount_; }
96 bool consumeCompleted();
98 int consumeLooped();
99
101 SpriteClip *getClip() const { return clip_; }
103 int getClipFrame() const { return clipFrame_; }
105 int getSheetFrame() const;
106
108 void bindQuad(graphics::Quad *quad);
110 void unbindQuad();
112 graphics::Quad *getBoundQuad() const { return boundQuad_; }
114 void bindSprite(graphics::Renderable2D *sprite);
115
117 void applyToQuad(graphics::Quad *quad) const;
118
124 [[nodiscard]] eve::Result<void> advance(const eve::SimulationStep &step);
126 [[nodiscard]] bool hasCurrentTick() const noexcept { return hasLastTick_; }
128 [[nodiscard]] eve::SimulationTick currentTick() const noexcept { return lastTick_; }
130 bool update(float dt);
131
132private:
133 friend class Animation;
134
135 void setOwner(Animation *owner) { owner_ = owner; }
136 Animation *owner() const { return owner_; }
137
138 void refreshFrame();
139 void syncBoundQuad();
140 float sampleSpeedCurve(float seconds) const;
141
142 struct SpeedKey {
143 float time = 0.f;
144 float value = 1.f;
145 };
146
147 Animation *owner_ = nullptr;
148 SpriteSheet *sheet_ = nullptr;
149 SpriteClip *clip_ = nullptr;
150 graphics::Quad *boundQuad_ = nullptr;
151 graphics::Renderable2D *boundSprite_ = nullptr;
152 float speed_ = 1.f;
153 float time_ = 0.f;
154 int clipFrame_ = -1;
155 bool playing_ = false;
156 bool paused_ = false;
157 bool finished_ = false;
158 bool loopOverride_ = false;
159 bool loopValue_ = true;
160 int loopCount_ = 0;
161 int pendingLoops_ = 0;
162 bool pendingComplete_ = false;
163 std::vector<SpeedKey> speedCurve_;
164 float speedCurveTime_ = 0.f;
165 bool speedCurveLoop_ = true;
166 std::string speedCurveInterpolation_ = "linear";
167 SpriteClip *queuedClip_ = nullptr;
168 std::string pendingEvent_;
170 bool hasLastTick_ = false;
171
172 bool updateUnchecked(float dt);
173};
174
175} // namespace eve::animation
double value
#define EVENGINE_API_WORLD
Definition Export.h:109
glm::vec4 clip
Common time values and an injectable deterministic simulation clock.
float step
Definition TreeMesh.cpp:314
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Animation module — tween factory + 2D sprite-sheet / Spine + 3D skeletal playback (player / state mac...
Definition Animation.h:80
2D sprite-sheet clip player.
Definition SpriteAnim.h:26
SpriteSheet * getSheet() const
Returns the sheet.
Definition SpriteAnim.h:39
bool isFinished() const
True when finished.
Definition SpriteAnim.h:92
int getLoopCount() const
Return loop boundaries crossed since play started.
Definition SpriteAnim.h:94
int getClipFrame() const
Index inside the current clip (0..clipFrameCount-1), or -1.
Definition SpriteAnim.h:103
float getSpeed() const
Returns the speed.
Definition SpriteAnim.h:55
eve::SimulationTick currentTick() const noexcept
Last scheduler tick consumed by this sprite animation.
Definition SpriteAnim.h:128
graphics::Quad * getBoundQuad() const
Returns the bound quad.
Definition SpriteAnim.h:112
SpriteAnim & operator=(const SpriteAnim &)=delete
SpriteClip * getClip() const
Returns the clip.
Definition SpriteAnim.h:101
bool isPlaying() const
True when playing.
Definition SpriteAnim.h:88
bool isPaused() const
True when paused.
Definition SpriteAnim.h:90
void setSpeedCurveLoop(bool loop)
Choose whether speed-curve time wraps after its last key.
Definition SpriteAnim.h:63
bool hasCurrentTick() const noexcept
Whether this sprite animation has consumed a scheduler step.
Definition SpriteAnim.h:126
SpriteAnim(const SpriteAnim &)=delete
float getTime() const
Returns the time.
Definition SpriteAnim.h:81
Named 2D frame sequence referencing SpriteSheet frame indices. Script type: SpriteClip.
Definition SpriteClip.h:17
Sprite-sheet / texture-atlas frame table (pixel rects).
Definition SpriteSheet.h:23
static constexpr StrongUint64 zero() noexcept
Returns the zero value for this strong type.
Pixel-space sub-rectangle of a Texture (atlas cell / sprite frame). UV conversion uses the texture's ...
Definition Quad.h:11
Default renderable entity for declarative 2D sprites / solid quads.
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
One deterministic fixed-step emitted by SimulationClock.
Definition Time.h:158