Change sprite color
armond

Hi guys! I'm not sure what it is exactly I need. I only know that I want to change the color of my already loaded sprite. If you're wondering why, here's the reason...

I have a bullet sprite. Let's say, when the player shoots that bullet it's colored blue(the default color from the bitmap including some shading). But when the enemy shoots that bullet I want it colored red(and the shading to follow). I want this to happen in the draw() method of my sprite. How can I achieve this? Thanks!

GullRaDriel
int change_color( BITMAP *spr , int orig_col , int final_col )
{
    for( it_x = 0 ; it_x < spr -> w ; it_x ++ )
    {
        for( it_y = 0 ; it_y < spr -> h ; it_y ++ )
        {
            if( getpixel( spr , it_x , it_y ) == orig_col )
                putpixel( spr , it_x , it_y , final_col );
        }
    }
}

Just add some sort of percentage thing.

Jonatan Hedborg

I should point out that you would be wise to make a copy of the bullet-bitmap and change the color of that (so you don't use that function once per enemy bullet per frame).

Another way to do it is to read in each pixel's color value, convert it to HSV, rotate the H part a certain amount (or simply set it to a specific value), convert it back to RGB and write it to the target bitmap.

Johan Halmén

Just prerender it with a decent graphic editor.

gnolam
Onewing
Quote:

draw_lit_sprite()

Seconded, this should be all you need for what you want to do.

Thread #591254. Printed from Allegro.cc