From 765485ced528ca2f4cf644a1503b9446c5826731 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Sun, 22 Sep 2024 10:58:21 +0200 Subject: spritesheet werkt --- resource-manager/main.cpp | 51 ++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 23 deletions(-) (limited to 'resource-manager/main.cpp') 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 #include #include #include +#include #include #include #include #include - -int main(){ +int main() { SDL_Init(SDL_INIT_VIDEO); - ResourceManager* rm = new ResourceManager; - + ResourceManager * rm = new ResourceManager; - Image* img = static_cast(rm->Load("../img.png")); + //Image* img = rm->Load("../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; } -- cgit v1.2.3