sprite documentation added as well as copy function
This commit is contained in:
parent
f337113932
commit
8d5190e405
4 changed files with 58 additions and 18 deletions
|
|
@ -332,8 +332,7 @@ int32_t ARC_Sprite_Read(ARC_Config* config, const char *data, ARC_StringSubstr *
|
|||
((ARC_Sprite *) *value)->frameIndex = malloc(sizeof(uint32_t));
|
||||
|
||||
((ARC_Sprite *) *value)->spritesheet = spritesheet;
|
||||
((ARC_Sprite *) *value)->frames = bounds->data;
|
||||
((ARC_Sprite *) *value)->frameSize = bounds->size;
|
||||
((ARC_Sprite *) *value)->frames = bounds;
|
||||
*((ARC_Sprite *) *value)->frameIndex = 0;
|
||||
|
||||
ARC_Rect *ttt = (ARC_Rect *)bounds->data;
|
||||
|
|
@ -436,7 +435,6 @@ int32_t ARC_Sprite_Delete(ARC_Config* config, const char* data, ARC_StringSubstr
|
|||
|
||||
if(!bounds){
|
||||
free(sprite->frames);
|
||||
free(sprite->frameSize);
|
||||
}
|
||||
|
||||
free(sprite->frameIndex);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
#include "arc/math/rectangle.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void ARC_Sprite_Create(ARC_Sprite **sprite, ARC_Spritesheet *spritesheet, ARC_Rect *frames){
|
||||
void ARC_Sprite_Create(ARC_Sprite **sprite, ARC_Spritesheet *spritesheet, ARC_Array *frames){
|
||||
*sprite = (ARC_Sprite *)malloc(sizeof(ARC_Sprite));
|
||||
(*sprite)->spritesheet = spritesheet;
|
||||
(*sprite)->frames = frames;
|
||||
|
|
@ -18,26 +18,29 @@ void ARC_Sprite_Destroy(ARC_Sprite *sprite){
|
|||
free(sprite);
|
||||
}
|
||||
|
||||
void ARC_Sprite_Copy(ARC_Sprite **newSprite, ARC_Sprite *oldSprite){
|
||||
*newSprite = (ARC_Sprite *)malloc(sizeof(ARC_Sprite));
|
||||
(*newSprite)->spritesheet = oldSprite->spritesheet;
|
||||
(*newSprite)->frames = oldSprite->frames;
|
||||
(*newSprite)->frameIndex = (uint32_t *)malloc(sizeof(uint32_t));
|
||||
*(*newSprite)->frameIndex = *oldSprite->frameIndex;
|
||||
}
|
||||
|
||||
void ARC_Sprite_Render(ARC_Sprite *sprite, ARC_Renderer *renderer, ARC_Rect *renderBounds){
|
||||
ARC_Rect *temp = &sprite->frames[*sprite->frameIndex];
|
||||
SDL_RenderCopy(renderer->renderer, sprite->spritesheet->texture, (SDL_Rect *)&sprite->frames[*sprite->frameIndex], (SDL_Rect *)renderBounds);
|
||||
ARC_Rect *temp = (ARC_Rect *)sprite->frames->data + *sprite->frameIndex;
|
||||
SDL_RenderCopy(renderer->renderer, sprite->spritesheet->texture, (SDL_Rect *)sprite->frames->data + *sprite->frameIndex, (SDL_Rect *)renderBounds);
|
||||
}
|
||||
|
||||
void ARC_Sprite_IterateFrame(ARC_Sprite *sprite){
|
||||
++*sprite->frameIndex;
|
||||
|
||||
if(*sprite->frameIndex == *sprite->frameSize){
|
||||
if(*sprite->frameIndex == *sprite->frames->size){
|
||||
*sprite->frameIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ARC_Sprite_SetFrames(ARC_Sprite *sprite, ARC_Array *frames){
|
||||
sprite->frames = frames->data;
|
||||
*sprite->frameIndex = 0;
|
||||
}
|
||||
|
||||
ARC_Rect *ARC_Sprite_GetBounds(ARC_Sprite *sprite){
|
||||
return sprite->frames + *sprite->frameIndex;
|
||||
return (ARC_Rect *)sprite->frames->data + *sprite->frameIndex;
|
||||
}
|
||||
|
||||
#endif // ARC_SDL
|
||||
Loading…
Add table
Add a link
Reference in a new issue