|
SDLGameEngine
|
Sprite handling. More...
Data Structures | |
| struct | SGESPRITEWAYPOINT |
| a sprite waypoint More... | |
| struct | SGESPRITE |
Functions | |
| SGESPRITE * | sgeSpriteNew (void) |
| create a new empty sprite | |
| SGESPRITE * | sgeSpriteNewFile (SGEFILE *f, const char *filename) |
| create a new sprite from a file | |
| SGESPRITE * | sgeSpriteNewFileRange (SGEFILE *f, const char *templ, Uint32 start, Uint32 end) |
| create a new animated sprite from a range of images | |
| SGESPRITE * | sgeSpriteNewSDLSurface (SDL_Surface *surface) |
| create a new sprite from a SDL_Surface | |
| void | sgeSpriteDestroy (SGESPRITE *s) |
| destroy a sprite and release all resources | |
| SGESPRITEIMAGE * | sgeSpriteGetCurrentFrame (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 | |
| SGEARRAY * | sgeSpriteGetCurrentSpriteArray (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 | |
| SGESPRITE * | sgeSpriteDuplicate (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 | |
| SGEARRAY * | SGESPRITE::sprite |
| a SGEARRAY holding SGEARRAYS with the sprites | |
| SGEARRAY * | SGESPRITE::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 | |
Sprite handling.
| void sgeAnimatedSpriteIgnoreAlpha | ( | SGESPRITE * | s | ) |
switch all sprites of the current animation to NOT use alpha data for collision information
| s | a 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
| s | a 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
| s | a 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
| s | a 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.
add a new frame to the current anim bank from a sge archive file
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
| s | a pointer to SGESPRITE |
| f | a pointer to a SGEFILE |
| templ | a format string like you use it in printf |
| start | the first value of the range |
| end | the 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
| s | a pointer to SGESPRITE |
| surface | a 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
| s | a pointer to SGESPRITE |
| i | a 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
| s | a pointer to SGESPRITE |
| x | the x position of the way point |
| y | the 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
| s | a pointer to SGESPRITE |
| state | YES/NO depending on to animate the sprite or not |
Definition at line 412 of file sgesprite.c.
test collision between the bounding box of two sprites
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
| a | a pointer to SGESPRITE |
| b | a pointer to SGESPRITEIMAGE |
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
| s | a pointer to SGESPRITE |
Definition at line 290 of file sgesprite.c.
test a collision between two sprites
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
| a | a pointer to fist SGESPRITE |
| b | a pointer to SGESPRITEIMAGE |
Definition at line 261 of file sgesprite.c.
| void sgeSpriteDestroy | ( | SGESPRITE * | s | ) |
destroy a sprite and release all resources
| s | a 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
| s | a pointer to SGESPRITE |
| dest | a 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
| s | a pointer to SGESPRITE |
| rotation | the rotation of the sprite in radians as float |
| zoom | the zoom level of the sprite as float |
| dest | a 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
| s | a pointer to SGESPRITE |
| x | the x position to draw |
| y | the y position to draw |
| dest | a 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
| s | a pointer to SGESPRITE |
| x | the x position to draw |
| y | the y position to draw |
| rotation | the rotation of the sprite in radians as float |
| zoom | the zoom level of the sprite as float |
| dest | a 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.
duplicate (copy) a sprite
| s | a pointer to SGESPRITE |
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
| s | a pointer to SGESPRITE |
| frame | the frame to set |
Definition at line 420 of file sgesprite.c.
| Uint32 sgeSpriteGetAnimBank | ( | SGESPRITE * | s | ) |
get the index of the current anim bank
| s | a pointer to SGESPRITE |
Definition at line 408 of file sgesprite.c.
| SGESPRITEIMAGE* sgeSpriteGetCurrentFrame | ( | SGESPRITE * | s | ) |
get the current SGESPRITEIMAGE of the current frame
| s | a pointer to SGESPRITE |
Definition at line 111 of file sgesprite.c.
get the current array of frames
| s | a pointer to SGESPRITE |
Definition at line 389 of file sgesprite.c.
| Uint32 sgeSpriteGetNumberOfFrames | ( | SGESPRITE * | s | ) | [inline] |
get the number of frames in the current anim bank
| s | a pointer to SGESPRITE |
Definition at line 379 of file sgesprite.c.
| SDL_Surface* sgeSpriteGetSDLSurface | ( | SGESPRITE * | s | ) |
get the SDL_Surface of the current frame of a sprite
| s | a pointer to SGESPRITE |
Definition at line 186 of file sgesprite.c.
| void* sgeSpriteGetUserData | ( | SGESPRITE * | s | ) |
get custom user data from a sprite
| s | a pointer to SGESPRITE |
Definition at line 375 of file sgesprite.c.
| int sgeSpriteHeight | ( | SGESPRITE * | s | ) |
get the height of a sprite image
| s | a pointer to SGESPRITE |
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
| s | a pointer to SGESPRITE |
| x | the x position to move towards |
| y | the 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 sprite from a file
| f | a pointer to SGEFILE |
| filename | the filename of the image in the sge archive |
example:
SGESPRITE *s=sgeSpriteNewFile(myFile, "data/sprites/player.png");
Definition at line 39 of file sgesprite.c.
create a new animated sprite from a range of images
| f | a pointer to SGEFILE |
| templ | a format string like you use it in printf |
| start | the first value of the range |
| end | the last value of the range |
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
| surface | a pointer to SDL_Surface |
Definition at line 51 of file sgesprite.c.
| void sgeSpriteRemoveNextWayPoint | ( | SGESPRITE * | s | ) |
remove the next (aka current) way point from a sprite
| s | a 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
| s | a 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)
| s | a pointer to SGESPRITE |
| bank | the 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
| s | a pointer to SGESPRITE |
| fps | the 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
| s | a pointer to SGESPRITE |
| number | the 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
| s | a pointer to SGESPRITE |
| data | a 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
| s | a pointer to SGESPRITE |
| speed | the 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
| s | a 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
| s | a 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
| s | a pointer to SGESPRITE |
Definition at line 265 of file sgesprite.c.