getpixel() and putpixel()
Jeff Bernard

I'm trying to make it so the player can customize the hero's colors. So, they choose the red, green, and blue values for the hero, then a function goes through and changes the colors. I would think my function works, but for some reason it doesn't. I've tried adding an obscene rest() when before putpixel() is executed, to see if it actually is, and it skipped the obscene rest()'s, so I assume it's a problem with checking for which color should be changed:

1void changeColors(int newR, int newG, int newB)
2{
3 // check if the color actually needs to change
4 if (newR != hero.r || newG != hero.g || newB != hero.b)
5 {
6 // change the color values for the hero
7 hero.r = newR;
8 hero.g = newG;
9 hero.b = newB;
10 
11 // load the bmp that has each hero sprite on it because it's
12 // half the amount of pixels as each frame (i stretch_blit)
13 BITMAP* heroLibrary = load_bitmap("data\\hero.bmp", NULL);
14 
15 // make sure the colors aren't default orange(255,128,64)
16 if (hero.r != 255 && hero.g != 128 && hero.b != 64)
17 for (int j = 0; j < heroLibrary->h; j++)
18 for (int k = 0; k < heroLibrary->w; k++)
19 
20 // this is my problem line...
21 if (getr(getpixel(heroLibrary, k, j)) == 255 &&
22 getg(getpixel(heroLibrary, k, j)) == 128 &&
23 getb(getpixel(heroLibrary, k, j)) == 64)
24 
25 // change the color?
26 putpixel(heroLibrary, k, j, makecol(hero.r, hero.g, hero.b));
27 
28 // put the hero sprites into it's array
29 for (int i = 0; i < 16; i++)
30 if (i < 8)
31 stretch_blit(heroLibrary, hero.frame<i>, i*16, 0, 16, 16, 0, 0,
32 hero.frame<i>->w, hero.frame<i>->h);
33 else
34 stretch_blit(heroLibrary, hero.frame<i>, (i-8)*16, 16, 16, 16, 0, 0,
35 hero.frame<i>->w, hero.frame<i>->h);
36 destroy_bitmap(heroLibrary);
37 }
38}

CGamesPlay

if (newR != hero.r && newG != hero.g && newB != hero.b)Each of those should be OR. I.E. "if red is not the old red OR green is not...".

"data\\hero.bmp"That should be "data/hero.bmp"

Other than that it should work.

Jeff Bernard

Ah, thanks, I didn't notice that with my first check. I've changed the AND to OR now.

As for the double backslash, that's how I load all of my files. It's essentially the same thing as a single forward slash. I just prefer the double backslash because Windows uses backslashes in their address for folders.

I've made the change on the first line...but it still doesn't seem to reach putpixel().

EDIT-- I fixed the problem. Simple mistake in my code.

Thread #570532. Printed from Allegro.cc