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 594B

123456789101112131415161718192021222324252627282930313233
  1. #pragma once
  2. #include <SDL.h>
  3. #include <cygnet/Renderer.h>
  4. #include "common.h"
  5. #include "Clock.h"
  6. namespace Swan {
  7. class Animation {
  8. public:
  9. Animation(Cygnet::RenderSprite sprite, float interval, Cygnet::Mat3gf mat = {}):
  10. sprite_(sprite), interval_(interval), timer_(interval) {}
  11. void tick(float dt);
  12. void reset();
  13. void draw(Cygnet::Renderer &rnd, Cygnet::Mat3gf mat);
  14. private:
  15. Cygnet::RenderSprite sprite_;
  16. float interval_;
  17. float timer_;
  18. int frame_ = 0;
  19. };
  20. inline void Animation::draw(Cygnet::Renderer &rnd, Cygnet::Mat3gf mat) {
  21. rnd.drawSprite(sprite_, mat, frame_);
  22. }
  23. }