sprite flashing? SDL?

Started by
4 comments, last by _SKOTTIE_ 20 years, 6 months ago
im usuing SDL for a top down shooter. when the enemy gets hit or the player gets hit, i want the sprite to flash red kinda like in arcade games. i dont want to have to write animations and create pictures for this. is there any way to edit the pallete or something to get this flashing effect? (SDL) thanks!
Because you touch yourself at night!
Advertisement
In a few SDL shoot-em-ups, I''ve done something like this:

if(Flashing){  if(SDL_GetTicks()%500>250){    DrawSprite(imgid,x,y);  }else{    // Do nothing (so it''ll not be shown)    // or draw a reddened version.  }}else{  DrawSprite(imgid,x,y);} 
but there is no way to like edit the pallete at run time so it flashes red without making a seperate picture for it?
Because you touch yourself at night!
I don''t know if you can do that with SDL. If you''re in 256-color mode, it should be fairly simple (run through on one loop and set all colors to high red, then on the next return it to the standard palette) but I don''t know how you could do it with a 32-bit color scheme.
http://edropple.com
You''re best bet in a mode other than 256 color would probably be to perform a pre-processing pass on the sprite, and generate another surface containing red pixels wherever there are non-transparent pixels in the source image.

In 256 color, you could set every index entry that the sprite uses to the color red, but this is bad if other parts of the scene (landscape, other characters, etc...) use those same entries, as they will also flash red. So, a pre-generated "flash frame" would probably be your best bet here, too.

This method is trivial, and wouldn''t require any extra frames to be drawn by hand. Just load in the frame as usual, create another frame of equal dimensions, and fill it with red wherever there is a pixel in the source frame. Fill the remaining pixels with your transparent color (if using color-keying). Whenever a flash is needed, draw this frame.

Josh
vertexnormal AT linuxmail DOT org

Check out Golem at:
My cheapass website
Well, check my (in project) Shoot-em-up (demo for windows only):

http://seb.sevilla.free.fr/explode/explode15.rar

And contact me if you want the source of the "blinking" effect (SDL + 8bits-Graphics for the sprite)


------------------------
- Seby -
www.dfhi-bomber.fr.st

[edited by - theSeby on September 24, 2003 3:28:32 AM]
------------------------ - Seby -www.dfhi-bomber.fr.st

This topic is closed to new replies.

Advertisement