parent
51c1e04f61
commit
b87217ff90
@ -0,0 +1,2 @@ |
||||
#include "animator.hpp" |
||||
#include "constants.hpp" |
@ -0,0 +1,27 @@ |
||||
#pragma once |
||||
#include <fmt/core.h> |
||||
|
||||
struct Animator { |
||||
int width = 0; |
||||
int height = 0; |
||||
int max_frames = 0; |
||||
size_t count = 0; |
||||
int frame = 0; |
||||
bool playing = false; |
||||
|
||||
inline void step(sf::Sprite& sprite, int rect_x, int rect_y, int rect_w, int rect_h) { |
||||
if(playing) { |
||||
count++; |
||||
frame = ((count / 4) % max_frames); |
||||
playing = frame != 0; |
||||
} |
||||
|
||||
sprite.setTextureRect(sf::IntRect({ |
||||
{rect_x + frame * width, rect_y}, |
||||
{rect_w, rect_h}})); |
||||
} |
||||
|
||||
inline void play() { |
||||
playing = true; |
||||
} |
||||
}; |
After Width: | Height: | Size: 316 KiB |
Loading…
Reference in new issue