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.cc 486B

1234567891011121314151617181920212223242526272829
  1. #include "Animation.h"
  2. #include "Win.h"
  3. #include "gfxutil.h"
  4. namespace Swan {
  5. void Animation::tick(float dt) {
  6. timer_ -= dt;
  7. if (timer_ <= 0) {
  8. timer_ += interval_;
  9. frame_ += 1;
  10. if (frame_ >= resource_.numFrames_)
  11. frame_ = 0;
  12. }
  13. }
  14. void Animation::draw(const Vec2 &pos, Win &win) {
  15. SDL_Rect rect = resource_.frameRect(frame_);
  16. win.showTexture(pos, resource_.texture_.get(), &rect, { .flip = flip_ });
  17. }
  18. void Animation::reset() {
  19. timer_ = interval_;
  20. frame_ = 0;
  21. }
  22. }