Loading...
Searching...
No Matches
spritesheet.c File Reference
`#include "arc/graphics/spritesheet.h"`
`#include "spritesheet.h"`
`#include "renderer.h"`
`#include "arc/math/point.h"`
`#include <SDL.h>`
`#include <SDL_image.h>`
`#include <stdlib.h>`

Go to the source code of this file.

## Functions

void | ARC_Spritesheet_CreateFromFile (ARC_Spritesheet **spritesheet, ARC_Renderer *renderer, ARC_String *path)
void | ARC_Spritesheet_Destroy (ARC_Spritesheet *spritesheet)
void | ARC_Spritesheet_RenderArea (ARC_Spritesheet *spritesheet, ARC_Rect *sheetBounds, ARC_Renderer *renderer, ARC_Rect *renderBounds)
ARC_Point | ARC_Spritesheet_GetSize (ARC_Spritesheet *spritesheet)
uint32_t * | ARC_Spritesheet_GetTileSize (ARC_Spritesheet *spritesheet)

## Function Documentation

## ARC_Spritesheet_CreateFromFile()

void ARC_Spritesheet_CreateFromFile | ( | ARC_Spritesheet ** | spritesheet,
|  | ARC_Renderer * | renderer,
|  | ARC_String * | path )

Definition at line 11 of file spritesheet.c.

{
*spritesheet = (ARC_Spritesheet *)malloc(sizeof(ARC_Spritesheet));
IMG_Init(IMG_INIT_PNG);
SDL_Surface *surface = IMG_Load(path->data);
if(!surface){
printf("Error: reading png '%s'\nSDL_Image Error: %s", path->data, IMG_GetError());
}
SDL_BlendMode tempMode;
SDL_GetSurfaceBlendMode(surface, &tempMode);
(*spritesheet)->texture = SDL_CreateTextureFromSurface((SDL_Renderer *)renderer, surface);
SDL_GetTextureBlendMode((*spritesheet)->texture, &tempMode);
SDL_FreeSurface(surface);
IMG_Quit();
ARC_Spritesheet_GetSize(*spritesheet);
}
ARC_Spritesheet_GetSize
ARC_Point ARC_Spritesheet_GetSize(ARC_Spritesheet *spritesheet)
Definition spritesheet.c:40
ARC_Spritesheet
Definition spritesheet.h:7
ARC_String::data
char * data
Definition string.h:15

References ARC_Spritesheet_GetSize(), and ARC_String::data.

## ARC_Spritesheet_Destroy()

void ARC_Spritesheet_Destroy | ( | ARC_Spritesheet * | spritesheet | ) |

Definition at line 31 of file spritesheet.c.

{
SDL_DestroyTexture(spritesheet->texture);
free(spritesheet);
}
ARC_Spritesheet::texture
SDL_Texture * texture
Definition spritesheet.h:8

References ARC_Spritesheet::texture.

## ARC_Spritesheet_GetSize()

ARC_Point ARC_Spritesheet_GetSize | ( | ARC_Spritesheet * | spritesheet | ) |

Definition at line 40 of file spritesheet.c.

{
ARC_Point size;
SDL_QueryTexture(spritesheet->texture, NULL, NULL, &size.x, &size.y);
return size;
}
ARC_Point
Definition point.h:10
ARC_Point::y
int32_t y
Definition point.h:12
ARC_Point::x
int32_t x
Definition point.h:11

References ARC_Spritesheet::texture, ARC_Point::x, and ARC_Point::y.

Referenced by ARC_Spritesheet_CreateFromFile().

## ARC_Spritesheet_GetTileSize()

uint32_t * ARC_Spritesheet_GetTileSize | ( | ARC_Spritesheet * | spritesheet | ) |

Definition at line 46 of file spritesheet.c.

{
return spritesheet->size;
}
ARC_Spritesheet::size
uint32_t * size
Definition spritesheet.h:9

References ARC_Spritesheet::size.

## ARC_Spritesheet_RenderArea()

void ARC_Spritesheet_RenderArea | ( | ARC_Spritesheet * | spritesheet,
|  | ARC_Rect * | sheetBounds,
|  | ARC_Renderer * | renderer,
|  | ARC_Rect * | renderBounds )

Definition at line 36 of file spritesheet.c.

{
SDL_RenderCopy((SDL_Renderer *)renderer, spritesheet->texture, (SDL_Rect *)sheetBounds, (SDL_Rect *)renderBounds);
}

References ARC_Spritesheet::texture.