载入中...
搜索中...
未找到
SpriteClip.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include <string>
6#include <unordered_map>
7#include <vector>
8
9namespace eve::animation {
10
11class SpriteSheet;
12
18public:
20 explicit SpriteClip(const std::string &name = "");
22 ~SpriteClip() = default;
23
24 SpriteClip(const SpriteClip &) = delete;
25 SpriteClip &operator=(const SpriteClip &) = delete;
26
28 void setName(const std::string &name);
30 std::string getName() const { return name_; }
31
33 void setLoop(bool loop) { loop_ = loop; }
35 bool getLoop() const { return loop_; }
36
38 void addFrame(int sheetFrameIndex, float duration = 0.1f);
39
41 void addFrameByName(SpriteSheet *sheet, const std::string &frameName, float duration = 0.1f);
42
44 void addRange(int firstSheetFrame, int lastSheetFrame, float fps);
46 void setFPS(float fps);
48 float getFPS() const;
50 void addEvent(int clipFrame, const std::string &name);
52 std::string getEvent(int clipFrame) const;
53
55 void clear();
56
58 int getFrameCount() const { return static_cast<int>(frames_.size()); }
60 int getSheetFrame(int index) const;
62 float getFrameDuration(int index) const;
64 float getDuration() const;
65
70 int frameAtTime(float timeSeconds) const;
71
73 float wrapTime(float timeSeconds) const;
74
75private:
76 struct Entry {
77 int sheetFrame = 0;
78 float duration = 0.1f;
79 };
80
81 void checkIndex(int index) const;
82
83 std::string name_;
84 bool loop_ = true;
85 std::vector<Entry> frames_;
86 std::unordered_map<int, std::string> events_;
87};
88
89} // namespace eve::animation
float duration
#define EVENGINE_API_WORLD
Definition Export.h:109
std::string name
uint32_t index
Named 2D frame sequence referencing SpriteSheet frame indices. Script type: SpriteClip.
Definition SpriteClip.h:17
SpriteClip(const SpriteClip &)=delete
~SpriteClip()=default
Sprite clip.
std::string getName() const
Returns the name.
Definition SpriteClip.h:30
void setLoop(bool loop)
Sets the loop.
Definition SpriteClip.h:33
int getFrameCount() const
Returns the frame count.
Definition SpriteClip.h:58
bool getLoop() const
Returns the loop.
Definition SpriteClip.h:35
SpriteClip & operator=(const SpriteClip &)=delete
Sprite-sheet / texture-atlas frame table (pixel rects).
Definition SpriteSheet.h:23