This is a simple Sprite class that I use for game development in C++ using SDL (www.libsdl.org).
Features include sprite animation, rotation, stretching, transparencies, and other commonly used sprite functions.
one hour payday loans
I hope this is somewhat useful. The source is available and should be fairly simple to work with.
Feel free to modify it however you want. please comment about any bugs are suggestions that you have. Thanks.
Clone from GitHub HERE
To view a demo of some of the Sprites classes features, and have access to some sample Bitmap images used with the Sprite library, download the following zip file. It also contains the project settings that I used in Dev C++ and SDL 1.2.12 to compile.
All examples use these sprites
Demo using special effects
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | // Initialize SDL, etc ... ... Sprite* s1 = new Sprite("sprites/samus_normal_run.bmp",10,60); // load a BMP that contains 10 frames // set the animation speed to 60 milliseconds // set RGB(255,0,255) as transparent, rotate 180 degrees, flip horizontal and reverse animation s1->setTransparency(255,0,255)->rotate180()->flipHorizontal()->reverseAnimation(); // etc ... ... // Main loop // clear background to black, RGB(0,0,0) SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0)); // animate and draw the sprite s1->animate()->draw(screen,0,0); SDL_Flip(screen); |

Posted in
Tags: 

This is a great library but where is the .lib/.a? I get undefined references.
Do you have SDL installed on your computer? If not just google “install SDL” or “setup SDL”
or, if you use linux it’s in the repositories.
In the case that you are using DeVcpp IDE (freeware), you can also automatically download and install SDL.
else you have to install it manually.
Also, don’t forget to set your linker options for the project, this is very important.
you will have to add -lSDL to the linker options.
you may also have to play around with the #include by changin it to
reply with any questions or problems, I’ll help you get everything set up.
(just let me know the IDE you are using)
Thanks
[...] Sprite Class in C++ using SDL [...]
Hello,
Good Job ! thank you very much for this. It ‘ll help me to leave my dear Pygame for a much powerfull env.
Glad to help, let me know if you have any problems with it, also occasionally check back for updates!
Also, this link is an invaluable link for using SDL. http://lazyfoo.net/SDL_tutorials/ It really helped me when I was switching from Basic to C/C++ for game dev.
Hi, just saying thanks for the class. I’m writing a Sprite class for SDL/OpenGL and yours was a great starting point!
Glad it was useful!
I wish I had time to go back and clean up the code some more for you.
Hi !
Thanks for sharing your work, it’s very usefull for my ongoing game development ! =))
However, I’ve found a bug in the SpriteEffects::pixelCollide() method.
When you test if the pixels of both sprites are transparents your’re doint it wrong with x value:
spriteB.isTransparentPixel(x-aX + …
spriteA.isTransparentPixel(x-aX + …
It results in checking pixel at the same x value for both sprites.
You need to use “x-bX” for spriteB :
spriteB.isTransparentPixel(x-bX + …
spriteA.isTransparentPixel(x-aX + …
best regards,
paic
Thanks for noticing and taking time to tell me! I’ll update the code!
When using the sprite class, I was wondering how would you load the character sprite and then show which line you would like to use as the animation? Such as i want to use the one where its back is facing towards us?
Without revisiting my old code, I would say that it should be pretty easy to add a set function to set the current animation.
On a side note actually while that code works you can check out my new graphics code on github. https://github.com/kennycason/legendofzelda/tree/master/src/engine/graphics/sprite the root directory is https://github.com/kennycason/legendofzelda
thanks!