Skip to content

cSprite

Stephen P edited this page Oct 13, 2021 · 7 revisions

Holds a single sprite for drawing.

Members

texture

SDL_Texture*
The SDL texture used for rendering.

textureFilepath

char[MAX_PATH]
The filepath to where the texture was imported from, if any. This especially is useful when exporting a c2DModel.

id

int
A field for some ID value. Not used internally. Could be sprite index or really anything else.

drawRect

cDoubleRect
The rectangle that stores where the sprite will be drawn and how wide and tall it is on the window.

srcClipRect

cDoubleRect
The rectangle that stores what sub-section of the texture provided is to be drawn. Very helpful for drawing individual sprites from a spritesheet.

center

cDoublePt
The center point of the sprite; where it rotates around. Defaults to {drawRect.w / 2.0, drawRect.h / 2.0}.

scale

double
The multiplicative scaling factor for drawing the sprite. To resize the sprite by a certain factor, you must just modify this variable.

flip

SDL_RenderFlip
The SDL flipping flag. SDL_FLIP_HORIZONTAL for mirroring across the y-axis, SDL_FLIP_VERTICAL for mirroring across the x-axis, and SDL_FLIP_NONE for no mirroring.

degrees

double
The rotation value of the sprite, in degrees clockwise from the +x axis.

renderLayer

int Defines which layer the sprite is rendered on. 0 -> Not rendered. 1 -> rendered last, 2 -> rendered after 1, etc. until the last layer renderLayers -> rendered first. renderLayers is defined when running initCoSprite(), and defaults to 5.

fixed

bool
If true, the sprite won't be affected by the camera. It's useful in creating a HUD, or letting something important stick to the screen without camera rotation, panning, zoom, or scaling coming into play.

global

bool If true, the sprite won't be freed by calls to destroyCScene(). This is useful for sprites defined globally such as UI elements. Because it is not freed by destroyCScene(), however, you must manually destroy it using destroyCSprite().

subclass

void*
Not used internally; this can be a pointer to any data or struct you wish to give it.

Functions

initCSprite

void initCSprite(cSprite* sprite, SDL_Texture* texture, char* textureFilepath, int id, cDoubleRect drawRect, cDoubleRect srcClipRect, cDoublePt* center, double scale, SDL_RendererFlip flip, double degrees, bool fixed, bool global, void* subclass, int drawPriority)
Initializes a sprite given a filled-in SDL_Texture*, optional filepath, optional ID, draw rectangle, source clipping rectangle, optional center point (pass NULL for default value), scale (1.0 for "normal"), SDL flip, rotation, fixed and global flags, optional subclass, and the draw priority.

destroyCSprite

void destroyCSprite(cSprite* sprite)
Destroys a given cSprite, de-allocating all the memory associated with it. This must be done individually if the sprite is not both in a cScene and de-allocated by destroying that cScene.

drawCSprite

void drawCSprite(cSprite sprite, cCamera camera, bool update, bool fixedOverride)
Draws a given cSprite with a camera. Pass true to update if you want the changes to be shown, or in other words, if you want the SDL_Renderer to be presented. Pass true to fixedOverride if you want to override the fixed flag in the cSprite itself and make it un-fixed. This is used internally by drawC2DModel() to pass in c2DModel.fixed.

checkCSpriteCollision

cDoubleVector checkCSpriteCollision(cSprite sprite1, cSprite sprite2)
See cDoubleVector.

Clone this wiki locally