A 2D tile-based sandbox game.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Animation.cc 438B

123456789101112131415161718192021222324252627
  1. #include "Animation.h"
  2. #include <cygnet/Renderer.h>
  3. namespace Swan {
  4. void Animation::tick(float dt) {
  5. timer_ -= dt;
  6. if (timer_ <= 0) {
  7. timer_ += interval_;
  8. frame_ += 1;
  9. if (frame_ >= sprite_.frameCount)
  10. frame_ = 0;
  11. }
  12. }
  13. void Animation::draw(const Vec2 &pos, Cygnet::Renderer &rnd) {
  14. rnd.drawSprite(sprite_, Cygnet::Mat3gf(mat_).translate(pos), frame_);
  15. }
  16. void Animation::reset() {
  17. timer_ = interval_;
  18. frame_ = 0;
  19. }
  20. }