Created
January 29, 2014 19:15
-
-
Save fkaa/8694821 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sprite_map[someid] = AnimatedSprite(Asset::load<Texture>("mychar.png"), glm::vec4(0, 48, 16, 16), 0.1f, 5, 16); | |
| sprite_map[someid].update(delta); // calls Sprite::update(float); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "sprite.h" | |
| Sprite::Sprite() { | |
| } | |
| Sprite::Sprite(const TexturePtr texture, const glm::vec4 source) : | |
| tex(texture), | |
| src(source) { | |
| } | |
| Sprite::~Sprite() { | |
| } | |
| AnimatedSprite::AnimatedSprite(const TexturePtr texture, const glm::vec4 source, float fps, int num, int size) : | |
| Sprite(texture, source), | |
| frame_time(fps), | |
| num_frames(num), | |
| tile_size(size), | |
| current_frame(0) { | |
| } | |
| AnimatedSprite::~AnimatedSprite() { | |
| } | |
| void AnimatedSprite::update(float delta) { | |
| printf("hierhjwoe"); | |
| time += delta; | |
| if (time > frame_time) { | |
| current_frame++; | |
| time = 0; | |
| if (current_frame > num_frames) { | |
| current_frame = 0; | |
| src.x -= (num_frames) * tile_size; | |
| } else { | |
| src.x += tile_size; | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef CLOBAT_SPRITE_H_ | |
| #define CLOBAT_SPRITE_H_ | |
| #include "glutil.h" | |
| #include "texture.h" | |
| class Sprite { | |
| public: | |
| Sprite(); | |
| Sprite(const TexturePtr texture, | |
| const glm::vec4 source); | |
| ~Sprite(); | |
| virtual void update(float delta) {} | |
| TexturePtr tex; | |
| glm::vec4 src; | |
| bool x_flip; | |
| }; | |
| class AnimatedSprite : public Sprite { | |
| public: | |
| AnimatedSprite(const TexturePtr texture, const glm::vec4 source, float fps, int num, int size); | |
| ~AnimatedSprite(); | |
| void update(float delta); | |
| private: | |
| const float frame_time; | |
| const int num_frames; | |
| int tile_size; | |
| int current_frame; | |
| float time; | |
| }; | |
| #endif /* defined CLOBAT_SPRITE_H_ */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment