SDLGameEngine

SgeSprite

Sprite handling. More...

Data Structures

struct  SGESPRITEWAYPOINT
 a sprite waypoint More...
struct  SGESPRITE

Functions

SGESPRITEsgeSpriteNew (void)
 create a new empty sprite
SGESPRITEsgeSpriteNewFile (SGEFILE *f, const char *filename)
 create a new sprite from a file
SGESPRITEsgeSpriteNewFileRange (SGEFILE *f, const char *templ, Uint32 start, Uint32 end)
 create a new animated sprite from a range of images
SGESPRITEsgeSpriteNewSDLSurface (SDL_Surface *surface)
 create a new sprite from a SDL_Surface
void sgeSpriteDestroy (SGESPRITE *s)
 destroy a sprite and release all resources
SGESPRITEIMAGEsgeSpriteGetCurrentFrame (SGESPRITE *s)
 get the current SGESPRITEIMAGE of the current frame
void sgeSpriteSetFPS (SGESPRITE *s, Uint32 fps)
 set the animation speed in frames per second
void sgeSpriteAddSDLSurface (SGESPRITE *s, SDL_Surface *surface)
 add a new frame to the current anim bank from a SDL_Surface
void sgeSpriteAddSpriteImage (SGESPRITE *s, SGESPRITEIMAGE *i)
 add a new frame to the current anim bank from a SGESPRITEIMAGE
void sgeSpriteAddFile (SGESPRITE *s, SGEFILE *f, const char *name)
 add a new frame to the current anim bank from a sge archive file
void sgeSpriteAddFileRange (SGESPRITE *s, SGEFILE *f, const char *templ, Uint32 start, Uint32 end)
 add new frames to the current anim bank from a range of files from a sge archive
SDL_Surface * sgeSpriteGetSDLSurface (SGESPRITE *s)
 get the SDL_Surface of the current frame of a sprite
void sgeSpriteDraw (SGESPRITE *s, SDL_Surface *dest)
 draw the sprite on a surface or screen
void sgeSpriteDrawXY (SGESPRITE *s, int x, int y, SDL_Surface *dest)
 draw the sprite on a surface or screen on a certain position
void sgeSpriteDrawRotoZoomed (SGESPRITE *s, float rotation, float zoom, SDL_Surface *dest)
 draw the sprite with zoom and rotation values
void sgeSpriteDrawXYRotoZoomed (SGESPRITE *s, int x, int y, float rotation, float zoom, SDL_Surface *dest)
 draw the sprite at a certain position with zoom and rotation values
void sgeAnimatedSpriteUseAlpha (SGESPRITE *s)
 switch all sprites of the current animation to use alpha data for collision information
void sgeAnimatedSpriteIgnoreAlpha (SGESPRITE *s)
 switch all sprites of the current animation to NOT use alpha data for collision information
int sgeSpriteBoxCollide (SGESPRITE *a, SGESPRITE *b)
 test collision between the bounding box of two sprites
int sgeSpriteCollide (SGESPRITE *a, SGESPRITE *b)
 test a collision between two sprites
int sgeSpriteBoxCollideSpriteImage (SGESPRITE *a, SGESPRITEIMAGE *b)
 test collision between the bounding box of a sprite and a spriteimage
int sgeSpriteCollideSpriteImage (SGESPRITE *a, SGESPRITEIMAGE *b)
 test a collision between a sprite and a spriteimage
int sgeSpriteWidth (SGESPRITE *s)
 get the with of a sprite image
int sgeSpriteHeight (SGESPRITE *s)
 get the height of a sprite image
void sgeSpriteAddWayPoint (SGESPRITE *s, int x, int y)
 add a way point to a sprite
void sgeSpriteRemoveNextWayPoint (SGESPRITE *s)
 remove the next (aka current) way point from a sprite
void sgeSpriteClearWayPoints (SGESPRITE *s)
 remove all remaining way points from a sprite
void sgeSpriteStartMovement (SGESPRITE *s, float speed)
 start the automatic movement of a sprite along its way points
void sgeSpriteAbortMovement (SGESPRITE *s)
 stop automatic movement of a sprite and remove all remaining way points
void sgeSpriteMoveTowards (SGESPRITE *s, int x, int y)
 move a sprite one step towards a certain coordinate
void sgeSpriteSetUserData (SGESPRITE *s, void *data)
 add custom user data to a sprite
void * sgeSpriteGetUserData (SGESPRITE *s)
 get custom user data from a sprite
void sgeSpriteUpdatePosition (SGESPRITE *s)
 copies the sprite position to the current frame
void sgeSpriteUpdate (SGESPRITE *s)
 updates a sprite without drawing it
Uint32 sgeSpriteGetNumberOfFrames (SGESPRITE *s)
 get the number of frames in the current anim bank
void sgeSpriteSetNumberOfFrames (SGESPRITE *s, Uint32 number)
 set the number of frames in the current anim bank
SGEARRAYsgeSpriteGetCurrentSpriteArray (SGESPRITE *s)
 get the current array of frames
void sgeSpriteSetAnimBank (SGESPRITE *s, Uint32 bank)
 switch to a anim bank (aka animation)
void sgeSpriteAddAnimBank (SGESPRITE *s)
 add a new anim bank (aka animation) the the sprite
Uint32 sgeSpriteGetAnimBank (SGESPRITE *s)
 get the index of the current anim bank
void sgeSpriteAnimate (SGESPRITE *s, int state)
 enable/disable animation of a sprite
void sgeSpriteResetAnimation (SGESPRITE *s)
 forces next frame to be frame 0 of the current anim bank
void sgeSpriteForceFrame (SGESPRITE *s, Uint32 frame)
 sets a specific frame of the current animation
SGESPRITEsgeSpriteDuplicate (SGESPRITE *s)
 duplicate (copy) a sprite

Variables

int SGESPRITEWAYPOINT::y
 y position of the waypoint
int SGESPRITE::y
 the y position of the sprite
Uint32 SGESPRITE::currentFrame
 the current frame of the durrent anim bank
SGEARRAYSGESPRITE::sprite
 a SGEARRAY holding SGEARRAYS with the sprites
SGEARRAYSGESPRITE::wayPoints
 a SGEARRAY holding the waypoints of the sprite
void * SGESPRITE::userData
 a void pointer for adding your own userdata to the sprite
int SGESPRITE::numberOfBanks
 the number of anim banks the sprite has
int SGESPRITE::currentBank
 the current anim bank of the sprite
int SGESPRITE::animate
 do animate the sprite (YES/NO)
Uint8 SGESPRITE::alpha
 the alpha of the sprite (0-255)
float SGESPRITE::moveSpeed
 the speed for automatic sprite movement

Detailed Description

Sprite handling.


Function Documentation

void sgeAnimatedSpriteIgnoreAlpha ( SGESPRITE s)

switch all sprites of the current animation to NOT use alpha data for collision information

Parameters:
sa pointer to SGESPRITE

Every sprite image can have a collision color defined to alternatively use this as collision transparent information.

Definition at line 242 of file sgesprite.c.

void sgeAnimatedSpriteUseAlpha ( SGESPRITE s)

switch all sprites of the current animation to use alpha data for collision information

Parameters:
sa pointer to SGESPRITE

This is default, you only need this if you have switched some not to use alpha info

Definition at line 233 of file sgesprite.c.

void sgeSpriteAbortMovement ( SGESPRITE s)

stop automatic movement of a sprite and remove all remaining way points

Parameters:
sa pointer to SGESPRITE

Definition at line 305 of file sgesprite.c.

void sgeSpriteAddAnimBank ( SGESPRITE s)

add a new anim bank (aka animation) the the sprite

Parameters:
sa pointer to SGESPRITE

Switches to the new anim bank immediately, all new added images will be added to the new anim bank

Definition at line 400 of file sgesprite.c.

void sgeSpriteAddFile ( SGESPRITE s,
SGEFILE f,
const char *  name 
)

add a new frame to the current anim bank from a sge archive file

Parameters:
sa pointer to SGESPRITE
fa pointer to a SGEFILE
namethe filename of the sprite image

Definition at line 132 of file sgesprite.c.

void sgeSpriteAddFileRange ( SGESPRITE s,
SGEFILE f,
const char *  templ,
Uint32  start,
Uint32  end 
)

add new frames to the current anim bank from a range of files from a sge archive

Parameters:
sa pointer to SGESPRITE
fa pointer to a SGEFILE
templa format string like you use it in printf
startthe first value of the range
endthe last value of the range

example:

 sgeSpriteAddFileRange(mySprite, myFile, "sprites/player%04d", 1, 60); 

Definition at line 141 of file sgesprite.c.

void sgeSpriteAddSDLSurface ( SGESPRITE s,
SDL_Surface *  surface 
)

add a new frame to the current anim bank from a SDL_Surface

Parameters:
sa pointer to SGESPRITE
surfacea pointer to a SDL_Surface

Definition at line 120 of file sgesprite.c.

void sgeSpriteAddSpriteImage ( SGESPRITE s,
SGESPRITEIMAGE i 
)

add a new frame to the current anim bank from a SGESPRITEIMAGE

Parameters:
sa pointer to SGESPRITE
ia pointer to the new SGESPRITEIMAGE

Definition at line 127 of file sgesprite.c.

void sgeSpriteAddWayPoint ( SGESPRITE s,
int  x,
int  y 
)

add a way point to a sprite

Parameters:
sa pointer to SGESPRITE
xthe x position of the way point
ythe y position of the way point

Way points are coordinates to let a sprite walk automatically along.

Definition at line 275 of file sgesprite.c.

void sgeSpriteAnimate ( SGESPRITE s,
int  state 
)

enable/disable animation of a sprite

Parameters:
sa pointer to SGESPRITE
stateYES/NO depending on to animate the sprite or not

Definition at line 412 of file sgesprite.c.

int sgeSpriteBoxCollide ( SGESPRITE a,
SGESPRITE b 
)

test collision between the bounding box of two sprites

Parameters:
aa pointer to fist SGESPRITE
ba pointer to second SGESPRITE
Returns:
0/1 if the bounding boxes of two sprites overlap

Used automatically by all pixel exact sprite collision functions for performance reasons.

Definition at line 247 of file sgesprite.c.

int sgeSpriteBoxCollideSpriteImage ( SGESPRITE a,
SGESPRITEIMAGE b 
)

test collision between the bounding box of a sprite and a spriteimage

Parameters:
aa pointer to SGESPRITE
ba pointer to SGESPRITEIMAGE
Returns:
0/1 if the bounding boxes of two images overlap

Used automatically by all pixel exact sprite collision functions for performance reasons.

Definition at line 257 of file sgesprite.c.

void sgeSpriteClearWayPoints ( SGESPRITE s)

remove all remaining way points from a sprite

Parameters:
sa pointer to SGESPRITE

Definition at line 290 of file sgesprite.c.

int sgeSpriteCollide ( SGESPRITE a,
SGESPRITE b 
)

test a collision between two sprites

Parameters:
aa pointer to fist SGESPRITE
ba pointer to second SGESPRITE
Returns:
0/1 if the sprites collide

example:

 if (sgeSpriteCollide(titanic, iceberg)) {
        printf("Abandon ship!\n");
 } 

Definition at line 252 of file sgesprite.c.

int sgeSpriteCollideSpriteImage ( SGESPRITE a,
SGESPRITEIMAGE b 
)

test a collision between a sprite and a spriteimage

Parameters:
aa pointer to fist SGESPRITE
ba pointer to SGESPRITEIMAGE
Returns:
0/1 if the images collide

Definition at line 261 of file sgesprite.c.

void sgeSpriteDestroy ( SGESPRITE s)

destroy a sprite and release all resources

Parameters:
sa pointer to SGESPRITE

Definition at line 57 of file sgesprite.c.

void sgeSpriteDraw ( SGESPRITE s,
SDL_Surface *  dest 
)

draw the sprite on a surface or screen

Parameters:
sa pointer to SGESPRITE
desta pointer to a SDL_Surface where it is drawn

Uses the position information from s->x and s->y

example:

Draw a sprite using the global SDL_Surface screen

 sgeSpriteDraw(mySprite, screen); 

Definition at line 193 of file sgesprite.c.

void sgeSpriteDrawRotoZoomed ( SGESPRITE s,
float  rotation,
float  zoom,
SDL_Surface *  dest 
) [inline]

draw the sprite with zoom and rotation values

Parameters:
sa pointer to SGESPRITE
rotationthe rotation of the sprite in radians as float
zoomthe zoom level of the sprite as float
desta pointer to a SDL_Surface where it is drawn

The rotation is in radians:

http://en.wikipedia.org/wiki/Radians

Definition at line 203 of file sgesprite.c.

void sgeSpriteDrawXY ( SGESPRITE s,
int  x,
int  y,
SDL_Surface *  dest 
)

draw the sprite on a surface or screen on a certain position

Parameters:
sa pointer to SGESPRITE
xthe x position to draw
ythe y position to draw
desta pointer to a SDL_Surface where it is drawn

Definition at line 198 of file sgesprite.c.

void sgeSpriteDrawXYRotoZoomed ( SGESPRITE s,
int  x,
int  y,
float  rotation,
float  zoom,
SDL_Surface *  dest 
) [inline]

draw the sprite at a certain position with zoom and rotation values

Parameters:
sa pointer to SGESPRITE
xthe x position to draw
ythe y position to draw
rotationthe rotation of the sprite in radians as float
zoomthe zoom level of the sprite as float
desta pointer to a SDL_Surface where it is drawn

The rotation is in radians:

http://en.wikipedia.org/wiki/Radians

example:

 sgeSpriteDrawXYRotoZoomed(mySprite, 100, 50, 3.14, 2.0, screen); 

Definition at line 207 of file sgesprite.c.

SGESPRITE* sgeSpriteDuplicate ( SGESPRITE s)

duplicate (copy) a sprite

Parameters:
sa pointer to SGESPRITE
Returns:
a exact copy of s

All resources are copied, so you could destroy sprite s and the new one still has all images

Definition at line 80 of file sgesprite.c.

void sgeSpriteForceFrame ( SGESPRITE s,
Uint32  frame 
) [inline]

sets a specific frame of the current animation

Parameters:
sa pointer to SGESPRITE
framethe frame to set

Definition at line 420 of file sgesprite.c.

Uint32 sgeSpriteGetAnimBank ( SGESPRITE s)

get the index of the current anim bank

Parameters:
sa pointer to SGESPRITE
Returns:
the index of the current anim bank

Definition at line 408 of file sgesprite.c.

SGESPRITEIMAGE* sgeSpriteGetCurrentFrame ( SGESPRITE s)

get the current SGESPRITEIMAGE of the current frame

Parameters:
sa pointer to SGESPRITE
Returns:
a pointer to SGESPRITEIMAGE of the current frame

Definition at line 111 of file sgesprite.c.

SGEARRAY* sgeSpriteGetCurrentSpriteArray ( SGESPRITE s) [inline]

get the current array of frames

Parameters:
sa pointer to SGESPRITE
Returns:
a pointer to SGEARRAY holding SGESPRITEIMAGE of all frames of the current anim bank

Definition at line 389 of file sgesprite.c.

Uint32 sgeSpriteGetNumberOfFrames ( SGESPRITE s) [inline]

get the number of frames in the current anim bank

Parameters:
sa pointer to SGESPRITE
Returns:
the number of frames in the current anim bank

Definition at line 379 of file sgesprite.c.

SDL_Surface* sgeSpriteGetSDLSurface ( SGESPRITE s)

get the SDL_Surface of the current frame of a sprite

Parameters:
sa pointer to SGESPRITE
Returns:
a pointer to the SDL_Surface of the current frame

Definition at line 186 of file sgesprite.c.

void* sgeSpriteGetUserData ( SGESPRITE s)

get custom user data from a sprite

Parameters:
sa pointer to SGESPRITE
Returns:
a void pointer to custom userdata

Definition at line 375 of file sgesprite.c.

int sgeSpriteHeight ( SGESPRITE s)

get the height of a sprite image

Parameters:
sa pointer to SGESPRITE
Returns:
the height of the image in pixels as int

Definition at line 270 of file sgesprite.c.

void sgeSpriteMoveTowards ( SGESPRITE s,
int  x,
int  y 
)

move a sprite one step towards a certain coordinate

Parameters:
sa pointer to SGESPRITE
xthe x position to move towards
ythe y position to move towards

Depends on the sprites move speed

Definition at line 311 of file sgesprite.c.

SGESPRITE* sgeSpriteNew ( void  )

create a new empty sprite

Returns:
a pointer to SGESPRITE

Definition at line 11 of file sgesprite.c.

SGESPRITE* sgeSpriteNewFile ( SGEFILE f,
const char *  filename 
)

create a new sprite from a file

Parameters:
fa pointer to SGEFILE
filenamethe filename of the image in the sge archive
Returns:
a pointer to SGESPRITE

example:

 SGESPRITE *s=sgeSpriteNewFile(myFile, "data/sprites/player.png"); 

Definition at line 39 of file sgesprite.c.

SGESPRITE* sgeSpriteNewFileRange ( SGEFILE f,
const char *  templ,
Uint32  start,
Uint32  end 
)

create a new animated sprite from a range of images

Parameters:
fa pointer to SGEFILE
templa format string like you use it in printf
startthe first value of the range
endthe last value of the range
Returns:
a pointer to SGESPRITE

example:

 SGESPRITE *s=sgeSpriteNewFileRange(myFile, "sprites/player%04d", 1, 60); 

Definition at line 45 of file sgesprite.c.

SGESPRITE* sgeSpriteNewSDLSurface ( SDL_Surface *  surface)

create a new sprite from a SDL_Surface

Parameters:
surfacea pointer to SDL_Surface
Returns:
a pointer to SGESPRITE

Definition at line 51 of file sgesprite.c.

void sgeSpriteRemoveNextWayPoint ( SGESPRITE s)

remove the next (aka current) way point from a sprite

Parameters:
sa pointer to SGESPRITE

Definition at line 283 of file sgesprite.c.

void sgeSpriteResetAnimation ( SGESPRITE s)

forces next frame to be frame 0 of the current anim bank

Parameters:
sa pointer to SGESPRITE

Definition at line 416 of file sgesprite.c.

void sgeSpriteSetAnimBank ( SGESPRITE s,
Uint32  bank 
) [inline]

switch to a anim bank (aka animation)

Parameters:
sa pointer to SGESPRITE
bankthe index of the anim bank

Definition at line 394 of file sgesprite.c.

void sgeSpriteSetFPS ( SGESPRITE s,
Uint32  fps 
)

set the animation speed in frames per second

Parameters:
sa pointer to SGESPRITE
fpsthe frames per second the animation should play

Definition at line 115 of file sgesprite.c.

void sgeSpriteSetNumberOfFrames ( SGESPRITE s,
Uint32  number 
) [inline]

set the number of frames in the current anim bank

Parameters:
sa pointer to SGESPRITE
numberthe new number of frames

Definition at line 384 of file sgesprite.c.

void sgeSpriteSetUserData ( SGESPRITE s,
void *  data 
)

add custom user data to a sprite

Parameters:
sa pointer to SGESPRITE
dataa pointer to your data, cast to (void *)

Definition at line 371 of file sgesprite.c.

void sgeSpriteStartMovement ( SGESPRITE s,
float  speed 
)

start the automatic movement of a sprite along its way points

Parameters:
sa pointer to SGESPRITE
speedthe movement speed as float

The movement speed is a relative value depending on the games frames per second.

Definition at line 297 of file sgesprite.c.

void sgeSpriteUpdate ( SGESPRITE s)

updates a sprite without drawing it

Parameters:
sa pointer to SGESPRITE

You should call this every frame on every sprite you are NOT drawing but change position or want the animation to be continued.

Updates position and animation values without drawing the sprite.

Definition at line 162 of file sgesprite.c.

void sgeSpriteUpdatePosition ( SGESPRITE s) [inline]

copies the sprite position to the current frame

Parameters:
sa pointer to SGESPRITE

The frames and the sprite do have its own position values, this function copies the position information of the SGESPRITE to the current frame.

You normally do not need this function directly unless you are neither using sgeSpriteDraw (or the other drawing functions) nor sgeSpriteUpdate on your sprite.

Definition at line 154 of file sgesprite.c.

int sgeSpriteWidth ( SGESPRITE s)

get the with of a sprite image

Parameters:
sa pointer to SGESPRITE
Returns:
the width of the image in pixels as int

Definition at line 265 of file sgesprite.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines