This is the documentation for the SDLSpriteList class, designed for
SDL.
It is based on original documentation of CDXSpriteList.
Sprite lists are used to store sprites in a dynamic
fashion. A SDLSpriteList is a linked list of SDLSprite objects, which can
be added and removed at run-time.
SDLSprite is based on original sources from CDX and ported and modified for SDL by Regis Quercioli.
Tutorial
Here is a little code tutorial on how to use SDLSprite in your projects:
Initializing:
For each SpriteList you want :
SDLSpriteList projectile;
Add a sprite to the list :
projectile.AddSprite(bullet, 0, 128, 112, 4, -4, 0, 0, 100);
It adds the bullet sprite (already created with (for example): SDLSprite *bullet = new SDLSprite("bullet.bmp", 16, 16, 3);) with type 0, at pos X,Y : 128,112, at velocity X,Y : 4,-4, with State and Frame 0, and with a delay between two sprite animations of 100ms. You can add in a single SpriteList as many different sprites as you need.
Using the list:
LOOPING THE LIST: When using a sprite list you will often need to loop through the list and perform operations on each of the sprites in the list, such as updating their positions. The code below shows how to loop through a CDXSpriteList:
SDLSprite* Node;
for(Node = projectile.Next(); Node != projectile.List(); Node = Node->m_Next)
{
Node->m_PosX
+= Node->m_VelX;
Node->m_PosY
+= Node->m_VelY;
}
Suppress a sprite in the list:
Notice that if you intend to remove sprites from the list as you update them you must save a pointer to the next sprite in the list to prevent the loop from becoming lost. Example :
SDLSprite* Node;
SDLSprite* Save;
for(Node = projectile.Next(); Node != projectile.List(); Node = Node->m_Next)
{
if (Node->m_Type
== DEAD)
{
Save = Node->Next();
projectile.DelSprite(Node);
Node = Save;
}
}
SpriteList methods
Constructors/Destructors :
#include "SDLSprite.h"
class SDLSpriteList;