parent
80a0f2ba75
commit
83df9ff03b
@ -1,21 +0,0 @@ |
|||||||
#include "animator.hpp" |
|
||||||
#include "constants.hpp" |
|
||||||
#include <SFML/Audio.hpp> |
|
||||||
#include "dbc.hpp" |
|
||||||
|
|
||||||
void Animator::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}})); |
|
||||||
} |
|
||||||
|
|
||||||
void Animator::play(bool sound_too) { |
|
||||||
playing = true; |
|
||||||
if(sound_too) sound.play(); |
|
||||||
} |
|
@ -1,25 +0,0 @@ |
|||||||
#pragma once |
|
||||||
#include <SFML/Graphics/Sprite.hpp> |
|
||||||
#include <SFML/Audio.hpp> |
|
||||||
#include <string> |
|
||||||
|
|
||||||
struct Animator { |
|
||||||
int width = 0; |
|
||||||
int height = 0; |
|
||||||
int max_frames = 0; |
|
||||||
sf::SoundBuffer buffer; |
|
||||||
sf::Sound sound; |
|
||||||
size_t count = 0; |
|
||||||
int frame = 0; |
|
||||||
bool playing = false; |
|
||||||
|
|
||||||
Animator(int w, int h, int max, std::string sound_file) : |
|
||||||
width(w), height(h), max_frames(max), |
|
||||||
buffer(sound_file), |
|
||||||
sound(buffer) |
|
||||||
{ |
|
||||||
} |
|
||||||
|
|
||||||
void step(sf::Sprite& sprite, int rect_x, int rect_y, int rect_w, int rect_h); |
|
||||||
void play(bool sound_too=true); |
|
||||||
}; |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 107 KiB |
Loading…
Reference in new issue