struct sprite_t {
SDL_Texture* texture;
float x, y;
SDL_FPoint origin;
float sx, sy;
float rot;
depth_t depth;
SDL_Rect uv;
SDL_RendererFlip flip;
}
Fields
texture: SDL_Texture*
A pointer to the texture to render, or NULL
if the sprite should not be rendered.
Preferably managed by the engine's asset database, though this is not required.
Default value: NULL
x: float
horizontal position of the sprite.
Default value: 0
y: float
Vertical position of the sprite.
Default value: 0
origin: SDL_FPoint
The centre of transformation of the sprite. As multiple of scale.
Default value: {0, 0}
sx: float
Horizontal size of the sprite. In global units.
Default value: 1
sy: float
Vertical size of the sprite. In global units.
Default value: 1
rot: float
Rotation of the sprite around origin.
Default value: 0
depth: depth_t
The render depth of the sprite, higher is further back.
Default value: RLAYER_SPRITES
uv: SDL_Rect
The rectangle of the texture to sample.
Default value: {0,0,0,0}
flip: SDL_RendererFlip
The flipped state of the sprite.
Default value: SDL_FLIP_NONE
Functions
sprite_t sprite_default()
Initialize an empty sprite with all fields set to default. This sprite can be safely used but will not render anything.
sprite_t make_sprite(const char* file, float x, float y)
Create a new from an image asset filename and a position. This may allocate heap space managed in the asset database.
sprite_t sprite_from_spritesheet(spritesheet_t* sheet, int index)
Create a new sprite from a entry on a spritesheet. This will reference the texture from the spritesheet.
NOTE: only use this if you need to create a new sprite from scratch. If you want to change the index of the sprite on the spritesheet use get_srcrect_from
void draw_sprite(const sprite_t* this)
Render the sprite onto the screen. Respects the current render mode. If called during the UI render phase the result will be in screen coordinates. If drawn in the game draw phase the result will be in world coordinates.