sparrowSprite

SparrowSprite is about drawing sprites.  Sprites are small animations of surfaces with scaling and rotation.  Scale and rotation are more expensive, than just blitting, keep that in mind.  So rotation = 0 and scaling = SP_ONE (fixed point value!) will be fastest.  If you disable caching, it may need a lot of space, because every subsprite then owns it own copy of the surface.

Summary
sparrowSpriteSparrowSprite is about drawing sprites.
Types
spSubSpritea sprite consists of different subSprites.
spSpriteThe sprite struct itself.
spSpriteCollectionThis is a collection of different sprites of one kind, e.g the sprite of the character of your game.
Functions
spNewSpriteCreates a new (empty) sprite.
spDeleteSpriteDeletes a sprite and all subsprites.
spNewSubSpriteNoTilingCreates a new subSprite out of a whole surface.
spNewSubSpriteWithTilingCreates a new subSprite out of a part of a surface (tiling).
spNewSubSpriteTilingRowVery similar to spNewSubSpriteWithTiling, but instead of adding one part of a surface, multiple parts (“tiles”) of the same surface are added.
spUpdateSpriteUpdates the sprite animation.
spSetSpriteRotationSets the rotation of the sprite.
spSetSpriteZoomSets the zoom of the sprite.
spDrawSpriteDraws a sprite with z set and test.
spDrawSprite3DDraws a sprite with z set and test in 3d space.
spNewSpriteCollectionSometimes it is useful to encapsulated different sprites to one bundle, e.g.
spDeleteSpriteCollectionDeletes a collection.
spAddSpriteToCollectionThis adds a existing (!)
spRemoveSpriteFromCollectionRemoves a sprite from a collection.
spSelectSpriteSets the active sprite of the collection.
spActiveSpriteReturns the active sprite of the sprite Collection.
spLoadSpriteCollectionLoads the a sprite Collection from a ssc-file and returns it as a sprite collection.

Types

spSubSprite

a sprite consists of different subSprites.  Every subSprite contains one surface (or a part of it), a duration and an age.  If the age is greater than the duration, the next subSprite will be drawn.  Think of it as a frame of a sprite.

Variables

surface (SDL_Surface*)the surface of the subsprite
sx,sy (Sint32)the position in the surface to be drawn for tiling.  If sx is smaller than 0 no tilling is done
sw,sh (Sint32)the width and height of the part of the surface
duration (Sint32)the time the surface shall be seen.  E.g.  50 ms would mean an animation with 20 fps
age (Sint32)how long was this subsprite seeable yet?
before,next (spSubSprite*)internal linked list pointers

spSprite

The sprite struct itself.

Variables

wholeDuration (Sint32)the sum of all durations of all subSprites.  See spSubSprite for more about “duration”
wholeAge (Sint32)the whole age of the animation
maxWidth,maxHeight (Sint32)every subSprite can have different sizes.  These are the biggest width and height
rotation (Sint32)the rotation of the sprite in fixed point radiant
zoomX, zoomY (Sint32)the zoom of the sprite.  SP_ONE means no zoom
firstSub (spSubSprite*)double linked list of the subSprites.  See spSubSprite for more detailed information
momSub (spSubSprite*)the active subSprite (and image) to draw
name (char*)the name of the sprite.  Needed for spSpriteCollection
collection (spSpriteCollection*)the collection the sprite is saved in.  Can be NULL
next (spSprite*)pointer to the next sprite pointer in the linked list from the collection.  Do not change.

spSpriteCollection

This is a collection of different sprites of one kind, e.g the sprite of the character of your game.  In that case you can have different named sprites in this collection e.g. for running left, running right, jumping left, jumping right, standing left, standing right and so on and can easyly choose between them e.g. by calling

spSelectSprite(collection,"running left");

Variables

firstSprite (spSprite*)the first sprite in the collection
active (spSprite*)the choosen sprite
authorauthor of the sprite.  Doesn’t have to be set
licenselicense of the sprite.  Doesn’t have to be set
commentfor a comment.  Don’t have to be set

Functions

spNewSprite

PREFIX spSpritePointer spNewSprite(char *name)

Creates a new (empty) sprite.

Parameters

namethe name of the sprite.  Needed for finding in a collection, but not necessary for the sprite itself, so if not needed feel free to pass NULL

Returns

spSprite*Pointer to a spSprite struct

spDeleteSprite

PREFIX void spDeleteSprite(spSpritePointer sprite)

Deletes a sprite and all subsprites.  If the sprite is in a collection (see below), it is removed from there, too.

Parameters

spritethe sprite to be removed

spNewSubSpriteNoTiling

PREFIX spSubSpritePointer spNewSubSpriteNoTiling(spSpritePointer sprite,
SDL_Surface *surface,
Sint32 duration)

Creates a new subSprite out of a whole surface.

Parameters

spritethe sprite, in which the subsprite shall be added
surfacethe surface to be added.  It will be “copied” with spCopySurface.  See spCopySurface for more information about “copying” with enabled caching
durationthe duration of the subsprite in milliseconds

Returns

spSubSprite*a pointer to the created spSubSprite struct

See Also

spNewSubSpriteWithTiling, spNewSubSpriteTilingRow

spNewSubSpriteWithTiling

PREFIX spSubSpritePointer spNewSubSpriteWithTiling(spSpritePointer sprite,
SDL_Surface *surface,
Sint32 sx,
Sint32 sy,
Sint32 sw,
Sint32 sh,
Sint32 duration)

Creates a new subSprite out of a part of a surface (tiling).

Parameters

spritethe sprite, in which the subsprite shall be added
surfacethe surface, which part shall be added.  It will be “copied” with spCopySurface.  See spCopySurface for more information about “copying” with enabled caching
sx,syposition of the left top corner of the part of the surface to be added
w,hsize of the part to be added
durationthe duration of the subsprite in milliseconds

Returns

spSubSprite*a pointer to the created spSubSprite struct

See Also

spNewSubSpriteNoTiling, spNewSubSpriteTilingRow

spNewSubSpriteTilingRow

PREFIX void spNewSubSpriteTilingRow(spSpritePointer sprite,
SDL_Surface *surface,
Sint32 sx,
Sint32 sy,
Sint32 sw,
Sint32 sh,
Sint32 hopw,
Sint32 hoph,
Sint32 count,
Sint32 duration)

Very similar to spNewSubSpriteWithTiling, but instead of adding one part of a surface, multiple parts (“tiles”) of the same surface are added.

Parameters

spritethe sprite, in which the subsprites shall be added
surfacethe surface, which parts shall be added.  It will be “copied” with spCopySurface.  See spCopySurface for more information about “copying” with enabled caching
sx,syposition of the left top corner of the first part of the surface to be added
w,hsize of the parts to be added
hopwthe x distance to the next tile.  If you don’t use borders, hopw should be the same as w
hophthe y distance to the next tile.  If the right end of the surface is reached, but not all parts added this functions “jumps” hoph on the y-axis and resets the x-position, too (like a line break in the image).  If you don’t use borders, hoph should be the same as h
countthe number of subSprites to be added.
durationthe duration of the subsprite in milliseconds

See Also

spNewSubSpriteNoTiling, spNewSubSpriteWithTiling

spUpdateSprite

PREFIX void spUpdateSprite(spSpritePointer sprite,
Sint32 time)

Updates the sprite animation.

Parameters

spritea pointer to a spSprite struct to update
timethe elapsed time

spSetSpriteRotation

PREFIX void spSetSpriteRotation(spSpritePointer sprite,
Sint32 rotation)

Sets the rotation of the sprite.  Same as to sprite->rotation = …

Parameters

spritea pointer to a spSprite struct to update
rotationSint32 fixed point radian rotation to set

See Also

spSetSpriteZoom

spSetSpriteZoom

PREFIX void spSetSpriteZoom(spSpritePointer sprite,
Sint32 zoomX,
Sint32 zoomY)

Sets the zoom of the sprite.  Same as to sprite->zoomX = … or sprite->zoomY = …

Parameters

spritea pointer to a spSprite struct to update
zoomX,zoomYSint32 fixed point zoom of the sprite.  SP_ONE means no zoom

See Also

spSetSpriteRotation

spDrawSprite

PREFIX void spDrawSprite(Sint32 x,
Sint32 y,
Sint32 z,
spSpritePointer sprite)

Draws a sprite with z set and test.  For more information or deactivating see sparrowPrimitives.  The sprite is always drawn with the fastest possible way.  That means e.g. blitting, if no zoom and rotation is given.

Parameters

x,y,zposition on screen and z coordinate for z test
spritea pointer to a spSprite struct to update

See Also

spDrawSprite3D

spDrawSprite3D

PREFIX void spDrawSprite3D(Sint32 x,
Sint32 y,
Sint32 z,
spSpritePointer sprite)

Draws a sprite with z set and test in 3d space.  For more information or deactivating the z stuff see sparrowPrimitives.  The sprite is always drawn with the fastest possible way.  That means e.g. blitting, if no zoom and rotation is given.

Parameters

x,y,zposition in 3d space
spritea pointer to a spSprite struct to update

See Also

spDrawSprite

spNewSpriteCollection

PREFIX spSpriteCollectionPointer spNewSpriteCollection(void)

Sometimes it is useful to encapsulated different sprites to one bundle, e.g. if you have a character with different animationloops like running left, jumping left, running right, jumping right, etc.  These bundles are called “spriteCollections” in sparrow3d.  Every sprite can (but have not to be!) in one collection.  The name of the sprite is used to identify it, so keep in mind to give every sprite a unique name at creation time for this feature!

Returns

spSpriteCollection*a pointer to a fresh created spSpriteCollection

spDeleteSpriteCollection

PREFIX void spDeleteSpriteCollection(spSpriteCollectionPointer collection,
int keepSprites)

Deletes a collection.

Parameters

collectionthe collection to be removed
keepSpritesif 1 the sprites in the collection are kept, if 0 the sprites are deleted, too

spAddSpriteToCollection

PREFIX void spAddSpriteToCollection(spSpriteCollectionPointer collection,
spSpritePointer sprite)

This adds a existing (!) sprite to a collection.

Parameters

collectionthe collection the sprite shall be added to
spritethe sprite to add to the collection.  If the sprite is already in a collection, it is removed from the old collection

spRemoveSpriteFromCollection

PREFIX void spRemoveSpriteFromCollection(spSpritePointer sprite)

Removes a sprite from a collection.

Parameters

spritesprite to be removed from it’s collection.  The collection of the sprite is set to NULL.  The sprite is not deleted, just removed!  However, if you delete the sprite, it will be removed from it’s collection automaticly

spSelectSprite

PREFIX void spSelectSprite(spSpriteCollectionPointer collection,
char *name)

Sets the active sprite of the collection.

Parameters

collectioncollection to work with
namename of the sprite to be choosen.  If such a sprite doesn’t exist, no change is done

spActiveSprite

PREFIX spSpritePointer spActiveSprite(spSpriteCollectionPointer collection)

Returns the active sprite of the sprite Collection.  Same to collection->active, but looks nicer, don’t you think?  ;-)

Parameters

collectionthe collection, which active sprite you want to know

Returns

spSprite*Pointer to the active spSprite

spLoadSpriteCollection

PREFIX spSpriteCollectionPointer spLoadSpriteCollection(
   char *filename,
   SDL_Surface *fallback_surface
)

Loads the a sprite Collection from a ssc-file and returns it as a sprite collection.  Use the “exampleSprite.ssc” in the data-folder of sparrow3d for an example and documentation of the file format.

Parameters

filenamefile name of the ssc file
fallback_surfacethis surface will be used, if the image file mentioned in the ssc file is not found.

Returns spSpriteCollection* - pointer to the loaded spSpriteCollection

PREFIX spSpritePointer spNewSprite(char *name)
Creates a new (empty) sprite.
PREFIX void spDeleteSprite(spSpritePointer sprite)
Deletes a sprite and all subsprites.
PREFIX spSubSpritePointer spNewSubSpriteNoTiling(spSpritePointer sprite,
SDL_Surface *surface,
Sint32 duration)
Creates a new subSprite out of a whole surface.
PREFIX spSubSpritePointer spNewSubSpriteWithTiling(spSpritePointer sprite,
SDL_Surface *surface,
Sint32 sx,
Sint32 sy,
Sint32 sw,
Sint32 sh,
Sint32 duration)
Creates a new subSprite out of a part of a surface (tiling).
PREFIX void spNewSubSpriteTilingRow(spSpritePointer sprite,
SDL_Surface *surface,
Sint32 sx,
Sint32 sy,
Sint32 sw,
Sint32 sh,
Sint32 hopw,
Sint32 hoph,
Sint32 count,
Sint32 duration)
Very similar to spNewSubSpriteWithTiling, but instead of adding one part of a surface, multiple parts (“tiles”) of the same surface are added.
PREFIX void spUpdateSprite(spSpritePointer sprite,
Sint32 time)
Updates the sprite animation.
PREFIX void spSetSpriteRotation(spSpritePointer sprite,
Sint32 rotation)
Sets the rotation of the sprite.
PREFIX void spSetSpriteZoom(spSpritePointer sprite,
Sint32 zoomX,
Sint32 zoomY)
Sets the zoom of the sprite.
PREFIX void spDrawSprite(Sint32 x,
Sint32 y,
Sint32 z,
spSpritePointer sprite)
Draws a sprite with z set and test.
PREFIX void spDrawSprite3D(Sint32 x,
Sint32 y,
Sint32 z,
spSpritePointer sprite)
Draws a sprite with z set and test in 3d space.
PREFIX spSpriteCollectionPointer spNewSpriteCollection(void)
Sometimes it is useful to encapsulated different sprites to one bundle, e.g.
PREFIX void spDeleteSpriteCollection(spSpriteCollectionPointer collection,
int keepSprites)
Deletes a collection.
PREFIX void spAddSpriteToCollection(spSpriteCollectionPointer collection,
spSpritePointer sprite)
This adds a existing (!)
PREFIX void spRemoveSpriteFromCollection(spSpritePointer sprite)
Removes a sprite from a collection.
PREFIX void spSelectSprite(spSpriteCollectionPointer collection,
char *name)
Sets the active sprite of the collection.
PREFIX spSpritePointer spActiveSprite(spSpriteCollectionPointer collection)
Returns the active sprite of the sprite Collection.
PREFIX spSpriteCollectionPointer spLoadSpriteCollection(
   char *filename,
   SDL_Surface *fallback_surface
)
Loads the a sprite Collection from a ssc-file and returns it as a sprite collection.
a sprite consists of different subSprites.
This is a collection of different sprites of one kind, e.g the sprite of the character of your game.
The sprite struct itself.
PREFIX SDL_Surface* spCopySurface(SDL_Surface *surface)
This creates a “copy” of a surface.
SparrowPrimitives is for drawing primitives like triangles or quads (with and without texture), blitting or rotozooming of surfaces, lines, ellipses, rectangles and for everything it provides a zBuffer test and set.
Close