A 2D tile-based sandbox game.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Resource.h 839B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #pragma once
  2. #include <SDL2/SDL.h>
  3. #include <stdint.h>
  4. #include <string>
  5. #include <memory>
  6. #include "common.h"
  7. namespace Swan {
  8. class ImageResource {
  9. public:
  10. ImageResource(
  11. SDL_Renderer *renderer, const std::string &name,
  12. const std::string &path, int frame_height = -1);
  13. ImageResource(
  14. SDL_Renderer *renderer, const std::string &name,
  15. int w, int h, uint8_t r, uint8_t g, uint8_t b);
  16. void tick(float dt);
  17. std::unique_ptr<SDL_Surface, void (*)(SDL_Surface *)> surface_{nullptr, &SDL_FreeSurface};
  18. std::unique_ptr<SDL_Texture, void (*)(SDL_Texture *)> texture_{nullptr, &SDL_DestroyTexture};
  19. int frame_height_;
  20. int num_frames_;
  21. std::string name_;
  22. int frame_ = 0;
  23. static std::unique_ptr<ImageResource> createInvalid(Context &ctx);
  24. private:
  25. float switch_interval_ = 1;
  26. float switch_timer_ = switch_interval_;
  27. };
  28. }