still working on adding frames to config

This commit is contained in:
herbglitch 2022-11-29 14:50:29 -07:00
parent 0591b6ca6e
commit a70e2256e2
2 changed files with 27 additions and 0 deletions

27
src/graphics/sdl/sprite.c Normal file
View file

@ -0,0 +1,27 @@
#ifdef ARC_SDL
#include "arc/graphics/sdl/sprite.h"
#include "arc/graphics/sdl/spritesheet.h"
#include "arc/graphics/sdl/renderer.h"
#include <stdlib.h>
void ARC_Sprite_Create(ARC_Sprite **sprite, ARC_Spritesheet *spritesheet, ARC_Rect *frames){
*sprite = (ARC_Sprite *)malloc(sizeof(ARC_Sprite));
(*sprite)->spritesheet = spritesheet;
(*sprite)->frames = frames;
(*sprite)->frameIndex = (uint32_t *)malloc(sizeof(uint32_t));
*(*sprite)->frameIndex = 0;
}
void ARC_Sprite_Destroy(ARC_Sprite *sprite){
free(sprite);
}
void ARC_Sprite_Render(ARC_Sprite *sprite, ARC_Renderer *renderer, ARC_Rect *renderBounds){
SDL_RenderCopy(renderer->renderer, sprite->spritesheet->texture, (SDL_Rect *)sprite->frames, (SDL_Rect *)renderBounds);
}
ARC_Rect *ARC_Sprite_GetBounds(ARC_Sprite *sprite){
return sprite->frames + *sprite->frameIndex;
}
#endif // ARC_SDL