Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Change sprite color

This thread is locked; no one can reply to it. rss feed Print
Change sprite color
armond
Member #8,282
January 2007

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
Member #3,861
September 2003
avatar

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.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Jonatan Hedborg
Member #4,886
July 2004
avatar

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.

-------
Sweden: Free from the shackles of Democracy since 2008-06-18!

Johan Halmén
Member #1,550
September 2001

Just prerender it with a decent graphic editor.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

gnolam
Member #2,030
March 2002
avatar

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Onewing
Member #6,152
August 2005
avatar

Quote:

draw_lit_sprite()

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

------------
Solo-Games.org | My Tech Blog: The Digital Helm

Go to: