Allegro.cc Forums » Programming Questions » [A5] al_get_pixel

 Matthew Leverton Supreme Loser January 1999 Note that you can click on any of the related discussions in the online manual to see how a function is used with some context.```unsigned char r, g, b; al_unmap_rgb(col, &r, &g, &b); if (r == 0xff && g == 0x00 && b == 0x00) { } ``` You could create a function:```bool cmp_color(ALLEGRO_COLOR col, unsigned int h) { unsigned char r, g, b; al_unmap_rgb(col, &r, &g, &b); return r == ((h >> 16) & 0xff) && g == ((h >> 8) & 0xff) && b == h & 0xff; } if (cmp_color(c, 0xff0000)) { } ```
 Neil Roy Member #2,229 April 2002 I used this to check for any colour other than black (all zeros which is transparent in my game). I'm looking for anything other than zero to show a collision (two coloured pixels occupying the same location on overlapping sprites). I chose memcmp(). This won't work in all circumstances, but it worked well here. ALLEGRO_COLOR simply holds RGBA values.``` // sample a pixel from each object pixel[0] = al_get_pixel(object1->img, (over_left-object1->x)+cx, (over_top-object1->y)+cy); pixel[1] = al_get_pixel(object2->img, (over_left-object2->x)+cx, (over_top-object2->y)+cy); // We'll compare the memory of our pixels to our transparent structure and see if we have a // collision. If both memcmp() is true (non-zero) than we have a collision. if(memcmp(&pixel[0], &trans, sizeof(trans)) && memcmp(&pixel[1], &trans, sizeof(trans))) { collision=true; goto EXIT; } ``` ---Deluxe Pacman 1: https://www.dropbox.com/s/pvwhxfo3jqjjp1e/DPacman199b.zip?dl=0Deluxe Pacman 2: https://www.dropbox.com/s/8lzab2omy7ydnye/DeluxePacman2.zip?dl=0Donations: http://www.PayPal.me/NeilRoy