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.

Known problems:
None.

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;

SDLSpriteList() ;
Default constructor.
~SDLSpriteList() ;
Default constructor.
Operations:
SDLSprite* AddSprite(SDLSprite* pTile ,
int Type  = 0,

int PosX  = 0,
int PosY  = 0,
int VelX  = 0,
int VelY  = 0,
int State  = 0,
int Frame  = 0,
int Delay  = 0) ;
 
 Adds a sprite to the sprite list. Only a pointer to a SDLSprite object is required, however you can also set up the sprite as required.
 
void DelSprite(SDLSprite* pNode ) ;
 Removes a sprite from the list.
 
void Draw(SDLSurface* lpSDLS , DWORD ScrnWorldX , DWORD ScrnWorldY , WORD BltType ) ;
Draws all the sprites in the list to the surface pointed to by lpDDS.
 
SDLSprite* List() ;
 Gives the pointer of the list.
 
SDLSprite* Next() ;
 Gets the next sprite in the list.
 
SDLSprite* Prev() ;

           Gets the previous sprite in the list.
Data Members:
Public:
SDLSprite m_List  - The top of the list.

int m_nSprites  - The number of sprites in the list.