A 2D tile-based sandbox game.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Animation.h 647B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #pragma once
  2. #include <SFML/Graphics/Sprite.hpp>
  3. #include "common.h"
  4. #include "Asset.h"
  5. #include "Timer.h"
  6. namespace Swan {
  7. class Animation {
  8. public:
  9. enum class Flags {
  10. HFLIP = 1,
  11. };
  12. Animation() = default;
  13. Animation(int w, int h, double interval, const Asset &asset, int flags = 0) {
  14. init(w, h, interval, asset, flags);
  15. }
  16. void init(int w, int h, double interval, const Asset &asset, int flags = 0);
  17. void tick(double dt);
  18. void draw(Win &win);
  19. void reset();
  20. int width_, height_;
  21. private:
  22. double interval_;
  23. const Asset *asset_;
  24. int fcount_;
  25. int frame_ = 0;
  26. bool dirty_ = true;
  27. Timer timer_;
  28. sf::Sprite sprite_;
  29. };
  30. }