The
SDLSprite library
- SDLSprite ? What's this ?
The SDLSprite library in based on the CDXSprite library from the
excellent CDX project (but unlikely it's only for
Windows...).
This C++ class contains the datas and functions required to display
animated sprites. A SDLSprite object is created from BMP picture which is used to strore
data for the sprite.
Beware : All the sprite's frames must be the same width and height and stored in
the same BMP file.
Download SDLSprite 1.2b
(20Ko)
The SDLSprite-1.2.tar.gz file also contains another class :
SDLSpriteList 1.1 which permits 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.
- How to use it ? It's simple :
1) Put SDLSprite.cpp, SDLSprite.h, SDLSpriteList.cpp
and SDLSpriteList.h in your source directory.
2) Add this line at the beginning of your code :
#include "SDLSprite.h"
#include "SDLSpriteList.h"
3) Add SDLSprite.cpp and SDLSpriteList.cpp to your project (for example, if you use KDevelop just go to Project choose Add a file to project
and choose SDLSprite.cpp and SDLSpriteList.cpp in your source directory)
4) Compile and it works !
- What's new in SDLSprite-1.2b.tar.gz archive ?
This archive contents SDLSprite1.2 class, SDLSpriteList1.1 class and
(this is the newest thing) the Linux compiled library libSDLSprite.a
(and it's Makefile) which regroups those two
classes. So when you compile a program with SDLSprite and SDLSpriteList you don't need no
more nor to include SDLSprite.cpp and SDLSpriteList.cpp in your game directory neither in your
KDevelop project. BUT, you need to include libSDLSprite.a
for the linking phase with: -lSDLSprite (look at "How to Compile?" part))
libSDLSprite.a is due to Matt
Campbell who send me his Makefile. But that's not all, Matt report me a bug in
SDLSprite_Example1... so look down below. Thanks Matt :)
- What's new in SDLSprite 1.2 class ?
Before anything else, a remark :
programs created for SDLSprite 1.2 won't work with SDLSPrite 1.0. But in the other hand,
programs created for the 1.0 version will work with the 1.2 version.
Now the news :
- Sprite's shadow handling with InitShadow, SetShadowOffset,
SetShadowValue, It's automaticaly drawn by Draw (so don't worry :)
- Position and velocity variables are now float type (in order to use
velocity in pixel/sec rather than in pixel/frame in your programs).
- Add m_DelayStart var (for its use look at example 4)
But there is a very odd problem :
If the sprite's shadow goes out of the display, the sprite himself
disapear and only its shadow remains. I don't understand where this problem comes from...
If you find please E-Mail me :)
Examples using SDLSprite and
SDLSpriteList

Example 1
(36 Ko - Needs SDLSprite 1.2):
Change the mouse cursor by an animated butterfly.
Since 03/10/01, this example was modified because
Matt Campbell report me a bug... In fact, I had to modify this
ligne:
mouse->SetFrame((SDL_GetTicks()/mouse->m_Delay)%mouse->m_NbFrame);
// animation !!!
with:
mouse->SetFrame((SDL_GetTicks()/mouse->m_Delay)%mouse->m_NbTotFrame);
// animation !!!

Example 2 (37 Ko - Needs
SDLSprite 1.2):
- Moving of a car with the arrow keys.
- use the new functions of SDLSprite 1.2 to create a
shadow to the sprite
Example 3 (47 Ko - Needs
SDLSprite 1.2):
- use the left mouse button to move a car sprite (if the
left button is kept pressed the car follow the mouse cursor)
- use the new functions of SDLSprite 1.2 to create a shadow to the sprite
- if 'c' key pressed, change the setting of the shadow

Example 4 (48 Ko - Needs
SDLSprite 1.2 and SDLSpriteList 1.1):
- use the space key to create a new sprite
- if the car's sprite is hit, projectile is supressed and the car rotates
- How to compile the example in a terminal
mode without libSDLSprite.a?
1) Copy SDLSprite.cpp, SDLSprite.h, SDLSpriteList.cpp
and SDLSpriteList.h in the example folder.
2) Open a terminal.
3) Move to example's folder.
4) Type :
c++ -c
SDLSprite.cpp
c++ -c SDLSpriteList.cpp
c++ -c main.cpp
c++ -lSDL -lpthread -o example
SDLSprite.o SDLSpriteList.o main.o
5) Run the exemple by taping : ./example
- How to compile the example in a terminal mode with
libSDLSprite.a?
1) Copy SDLSprite.h and SDLSpriteList.h in the example folder.
2) Open a terminal.
3) Move to example's folder.
4) Type :
c++ -c
main.cpp
c++ -lSDL -lSDLSprite -lpthread -o
example main.o
5) Run the exemple by taping : ./example
- How to compile with KDevelop?
1) ### TODO ###
|