diff options
author | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-09-22 10:58:21 +0200 |
---|---|---|
committer | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-09-22 10:58:21 +0200 |
commit | 765485ced528ca2f4cf644a1503b9446c5826731 (patch) | |
tree | e9d35c04a8768afb38873daa31d1b47a3da93e54 /resource-manager/main.cpp | |
parent | 507a97739726feb74ffa91e317ead1773183ccbf (diff) |
spritesheet werkt
Diffstat (limited to 'resource-manager/main.cpp')
-rw-r--r-- | resource-manager/main.cpp | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/resource-manager/main.cpp b/resource-manager/main.cpp index 62426d1..6dc362b 100644 --- a/resource-manager/main.cpp +++ b/resource-manager/main.cpp @@ -2,56 +2,61 @@ #include "Image_asset.h" #include "resource_manager.h" +#include "spritesheet.h" #include <SDL.h> #include <SDL2/SDL_image.h> #include <SDL_events.h> #include <SDL_render.h> +#include <SDL_stdinc.h> #include <SDL_surface.h> #include <SDL_timer.h> #include <SDL_video.h> #include <cstddef> - -int main(){ +int main() { SDL_Init(SDL_INIT_VIDEO); - ResourceManager* rm = new ResourceManager; - + ResourceManager * rm = new ResourceManager; - Image* img = static_cast<Image*>(rm->Load("../img.png")); + //Image* img = rm->Load<Image>("../spritesheet_test.png"); //Resource* sound = rm->Load("/sound.ogg"); - bool quit = false; - + SDL_Event event; - SDL_Window* window = SDL_CreateWindow("Tessting resources", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, 0); + SDL_Window * window + = SDL_CreateWindow("Tessting resources", SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, 640, 480, 0); - SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0); - SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, img->surface); + SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, 0); + SpriteSheet spritesheet("../spritesheet_test.png", *renderer, 1, 4); + SDL_SetRenderDrawColor(renderer, 168, 230, 255, 255); + SDL_RenderClear(renderer); while (!quit) { - SDL_WaitEvent(&event); - - switch (event.type) { - case SDL_QUIT: - quit = true; - break; + Uint32 ticks = SDL_GetTicks(); + int sprite = (ticks / 100) % 4; + + //SDL_Rect srcrect = { sprite * 32, 0, 32, 64 }; + SDL_Rect dstrect = {10, 10, 32, 64}; + + while (SDL_PollEvent(&event) != NULL) { + switch (event.type) { + case SDL_QUIT: + quit = true; + break; + } } - SDL_RenderCopy(renderer, texture, NULL, NULL); + SDL_RenderClear(renderer); + spritesheet.select_sprite(sprite, 0); + spritesheet.draw_selected_sprite(renderer, &dstrect); SDL_RenderPresent(renderer); - - SDL_Delay(100); - } - SDL_DestroyTexture(texture); SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); SDL_Quit(); - - return 0; } |