aboutsummaryrefslogtreecommitdiffstats
path: root/include/components.hpp
diff options
context:
space:
mode:
authorAndy <drumsetmonkey@gmail.com>2016-12-23 08:42:15 -0500
committerAndy <drumsetmonkey@gmail.com>2016-12-23 08:42:15 -0500
commitd7d1b397197893f0ce49b28f762711b7a9ef1087 (patch)
tree6a14f9daf59cb1640f09e7f82c6325d93d0a62dc /include/components.hpp
parent691411cdb214178f2d10ab589943993039fe080e (diff)
parent6dd6d03bb1af3c1c482a67355446998eccc3288c (diff)
Sprites are good. Merged.
Diffstat (limited to 'include/components.hpp')
-rw-r--r--include/components.hpp41
1 files changed, 23 insertions, 18 deletions
diff --git a/include/components.hpp b/include/components.hpp
index 2a8680d..5c067dd 100644
--- a/include/components.hpp
+++ b/include/components.hpp
@@ -125,32 +125,35 @@ struct Solid {
};
struct SpriteData {
-
- SpriteData(std::string path, vec2 offset):
- offset(offset) {
- pic = Texture::loadTexture(path);
- size = Texture::imageDim(path);
+
+ 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 offset, vec2 size):
- offset(offset), size(size) {
- pic = Texture::loadTexture(path);
- vec2 tmpsize = Texture::imageDim(path);
+ SpriteData(std::string path, vec2 off, vec2 si):
+ size(si), offset(off) {
+ tex = Texture(path);
+ vec2 tmpsize = tex.getDim();
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;
}
- GLuint pic;
+ Texture tex;
+ vec2 size;
vec2 offset;
+
vec2 offset_tex;
- vec2 size;
vec2 size_tex;
};
@@ -168,7 +171,7 @@ struct Sprite {
Sprite(bool left = false)
: faceLeft(left) {}
- std::vector<std::pair<SpriteData, vec2>> getSprite() {
+ Frame getSprite() {
return sprite;
}
@@ -210,15 +213,17 @@ struct Sprite {
}
for (auto &s : sprite) {
+ const auto& size = s.first.tex.getDim();
+
if (s.second.x < st.x)
st.x = s.second.x;
if (s.second.y < st.y)
st.y = s.second.y;
- if (s.second.x + s.first.size.x > dim.x)
- dim.x = s.second.x + s.first.size.x;
- if (s.second.y + s.first.size.y > dim.y)
- dim.y = s.second.y + s.first.size.y;
+ if (s.second.x + size.x > dim.x)
+ dim.x = s.second.x + size.x;
+ if (s.second.y + size.y > dim.y)
+ dim.y = s.second.y + size.y;
}
return dim;
@@ -321,9 +326,9 @@ public:
class RenderSystem : public entityx::System<RenderSystem> {
private:
std::string loadTexString;
- std::atomic<GLuint> loadTexResult;
+ Texture loadTexResult;
public:
- GLuint loadTexture(const std::string& file);
+ Texture loadTexture(const std::string& file);
void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
};