I have a little getpixel problem:
the following condition crashes..
if(_getpixel32((BITMAP*)datafiles::sprites_enemies[game::enemies::enemies[enyNR].visual].dat, game::enemies::enemies[enyNR].Xpos - game::projectiles::projectiles[proNR].Xpos, game::enemies::enemies[enyNR].Ypos - game::projectiles::projectiles[proNR].Ypos) != makecol(255, 0, 255))
BUT if i replace != with == it "works"...
to bad i don't need == in this case..
and it doesn't respond like i want it to
as:
do stuff doesn't execute even if the pixel I'm trying to check is (255, 0, 255). getpixel looks up bitmaps with all color depths right?
i can't figure out what's wrong!
help appreciated! (duh)
_getpixel32 does not do any bounds checking, so it can crash if you use it improperly, but...
BUT if i replace != with == it "works"...
to bad i don't need == in this case..
If that's true, then the crash is in your dostuff() call.
]]>oops,
"(_getpixel32((BITMAP*)datafiles::sprites_enemies[game::enemies::enemies[enyNR].visual].dat,"
is "old", i now use getpixel.
strange... it no longer crashes. - -'..
but the more important problem still exists.
]]>Are you sure the color depth of the bitmap matches the screen's?
And of course, are you sure the pixel is 255,0,255?
]]>Are you sure the color depth of the bitmap matches the screen's?
i thought bitmaps where converted into the screens color depth?
using paint i can only save bitmaps into the 24-bit format..
(lost?)
And of course, are you sure the pixel is 255,0,255?
quite sure about that, when drawing them to the buffer the pixels doesn't get drawn and in 32 and 24 color depth isn't that an automatic event trigged by a pixel with maximum red and blue value resp minimum green when using draw_sprite()?
]]>i thought bitmaps where converted into the screens color depth?
They are, if you load them after you set the graphics mode.
]]>They are, if you load them after you set the graphics mode.
And that's what i do. :/
]]>Note that in 32-bit mode the fourth byte - the alpha value - is relevant too. (255, 0, 255, 255) and (255, 0, 255, 0) are very different colors according to the system.
]]>
Are the positions you passing within the image correct?
Try finding out what the read values are..
Note that in 32-bit mode the fourth byte - the alpha value - is relevant too. (255, 0, 255, 255) and (255, 0, 255, 0) are very different colors according to the system.
Noted. But am i not checking only for the other values?
even if the alpha channel exist it doesn't matter if i don't check for it. right/wrong?
Are the positions you passing within the image correct?
They probably are: i have a condition which checks if the point I'm trying to read is inside the bitmap (in this case it's an enemy's bitmap and the action point of a projectile) if it is inside it should be destroyed which it is (not including the second condition), the second condition is the getpixel dependent one:
and it always executes (if the first condition is true).
the first condition look like this:
//sorry for the unreadable stuff.. if(game::projectiles::projectiles[proNR].Xpos > game::enemies::enemies[enyNR].Xpos && game::projectiles::projectiles[proNR].Xpos < game::enemies::enemies[enyNR].Xpos + ((BITMAP*)datafiles::sprites_enemies[game::enemies::enemies[enyNR].visual].dat)->w && game::projectiles::projectiles[proNR].Ypos > game::enemies::enemies[enyNR].Ypos && game::projectiles::projectiles[proNR].Ypos < game::enemies::enemies[enyNR].Ypos + ((BITMAP*)datafiles::sprites_enemies[game::enemies::enemies[enyNR].visual].dat)->h )
Try finding out what the read values are..
Good idea, i will.
Thanks for your help!
]]>
Noted. But am i not checking only for the other values?
even if the alpha channel exist it doesn't matter if i don't check for it. right/wrong?
You're comparing a 32-bit integer to another 32-bit integer. Of course the entire thing is being taken into account.
]]>You're comparing a 32-bit integer to another 32-bit integer. Of course the entire thing is being taken into account.
I guess that makes sense in a way.. but how do i check the alpha value? _makecol32 still only accepts 3 values. :/
]]>makeacol32
... ><. thanks .
Is alpha 255 solid or is it 0?.
no matter which one i use the problem is the same as before. :/.
I'm going to check what values i get.
]]>I think what you want to compare is the non-alpha part of the pixel value. Since you use magic pink, the alpha channel isn't interesting at all (magic pink pixels are masked out regardless of alpha: in allegro, the alpha channel is only used for the alpha blender).
To be sure, you could bitwise-and the getpixel result with makeacol(255, 255, 255, 0) to mask out the alpha channel in the comparison. Example:
if (getpixel(bmp, x, y) & makeacol32(255, 255, 255, 0) == makeacol32(255, 0, 255, 0)) do_stuff();
]]>
Note that getpixel() is based on the pixel format of the bitmap you are getting the pixel from, while makecol() is based on the current screen format.
If you want your routine to be universal, you need to check the bitmap depth before comparing and the use the appropriate makecol#() command. For instance:
source_colour = getpixel(my_bitmap); switch (bitmap_color_depth(my_bitmap)) { case 8: test_colour = makecol8(255,0,255); break; case 15: test_colour = makecol15(255,0,255); break; case 16: test_colour = makecol16(255,0,255); break; case 24: test_colour = makecol24(255,0,255); break; case 32: { source_colour = makecol24(getr32(source_colour),getg32(source_colour),getb32(source_colour)); test_colour = makecol24(255,0,255); break; } } if (source_colour == test_colour) // Do Stuff
Also, makecol() takes a little CPU time. (Not much, a lot more if it's doing 8-bit conversions.) What you should do if you're using constants in makecol() is to get the values you're going to compare immediately after entering a graphics mode and store them into variables. That way, you can skip calling makecol() every time you want to make the comparison.
--- Kris Asick (Gemini)
--- http://www.pixelships.com
I got it to work after a while, the problem was simple as i didn't check for the right pixels :/.
if(getpixel((BITMAP*)datafiles::sprites_enemies[game::enemies::enemies[enyNR].visual].dat, (game::enemies::enemies[enyNR].Xpos + ((BITMAP*)datafiles::sprites_enemies[game::enemies::enemies[enyNR].visual].dat)->w) - game::projectiles::projectiles[proNR].Xpos, (game::enemies::enemies[enyNR].Ypos + ((BITMAP*)datafiles::sprites_enemies[game::enemies::enemies[enyNR].visual].dat)->h) - game::projectiles::projectiles[proNR].Ypos) != makecol(255, 0, 255))
Thanks for all your help!!
]]>