diff options
Diffstat (limited to 'include/components.hpp')
-rw-r--r-- | include/components.hpp | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/include/components.hpp b/include/components.hpp index bbf153a..5c067dd 100644 --- a/include/components.hpp +++ b/include/components.hpp @@ -125,12 +125,36 @@ struct Solid { }; struct SpriteData { + + SpriteData(std::string path, vec2 off): + offset(off) { + tex = Texture(path); + size = tex.getDim(); + + size_tex = vec2(1.0, 1.0); + + offset_tex.x = offset.x/size.x; + offset_tex.y = offset.y/size.y; + } + + SpriteData(std::string path, vec2 off, vec2 si): + size(si), offset(off) { + tex = Texture(path); + vec2 tmpsize = tex.getDim(); - SpriteData(std::string path, vec2 offset) - : tex(path), offset(offset) {} + size_tex.x = size.x/tmpsize.x; + size_tex.y = size.y/tmpsize.y; + + offset_tex.x = offset.x/tmpsize.x; + offset_tex.y = offset.y/tmpsize.y; + } Texture tex; + vec2 size; vec2 offset; + + vec2 offset_tex; + vec2 size_tex; }; using Frame = std::vector<std::pair<SpriteData, vec2>>; @@ -212,7 +236,7 @@ struct Sprite { //TODO struct Animate { // COMMENT - std::vector<Frame> frame; + std::vector<std::pair<uint, Frame>> frame; // COMMENT uint index; @@ -221,17 +245,19 @@ struct Animate { } // COMMENT - Frame nextFrame() { + void nextFrame(Frame sprite) { if (index < frame.size() - 1) { index++; } else { index = 0; } - return frame.at(index); + auto fa = frame.at(index); + if (sprite.size() > fa.first-1) + sprite.at(fa.first) = fa.second.at(fa.first); } - Frame firstFrame() { - return frame.front(); + void firstFrame(Frame sprite) { + sprite = frame.at(0).second; } }; |