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

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