you'll need to scan the entire bitmap for that color, when that pixel has the right color you need to compare if the x & y for that pixel is between the 4 points of your imaginary rectangle.
actually, scanning the rectangle only for that color would be faster and requires less checks.
The second option is certainly more efficient, but probably not efficient enough.
My idea was to have an image map for the background of a game, and then have an invisible duplicate map that was just black and white. a character can move around in the black areas, but not the white areas. So I would check to see if the character's sprite DestRect had hit any white pixels. If so, then the character wouldn't move.
The second option is certainly more efficient, but probably not efficient enough.
My idea was to have an image map for the background of a game, and then have an invisible duplicate map that was just black and white. a character can move around in the black areas, but not the white areas. So I would check to see if the character's sprite DestRect had hit any white pixels. If so, then the character wouldn't move.
Walls, floors, steps, other solid surfaces, right ? One of the possible solution is to partition your world in, say 8x8 or 16x16 whatever, square pieces, then assign byte value of each peace to 0 ( free ) or 1 (solid ), like that:
Solid( x, y )
you save a lot of mem and can check collisions very fast:
if Solid( x>>3, y>>3 ) = 1 then
handle collision
else
x = x + speed_x
y = y + speed_y
end if
>>3 - stands here for 3 times right shift e.g division by 8
well, source black-and-white image is what width/height ? 8192x8192 ? hardly believe poor phone can handle it ) on other hand 16x16 partition is 262144 bytes only
Sort of programm you or smbdy else can write for this purpose )
Well, lets face another approach. Think, your world solid areas can be described as array of rectangles ( or triangles if you have slopes ). Try to use Box2D - here is a lib for that, really cool 2D collision library
Another idea is to use BSP ( Binary Space Partition ) for world, really the best in speed/size especially for complex solid structures
frankly, BSP is very complex thing to understand and to implement, so i will recommend Box2D, especially because of lib ready and lot of docs/samples about this crossplatform lib around
just create something that's 1x,2x or 3x player width (from the next animation frame) and put the player mask inthere (1's) and add the enemy (also 1's)
when it's in that playerx-player.width to player+player.width boundery box to the map.
then all you need is a quick scan to see if there is a value equal to 2 which means a hit/collide (1 player + 1 enemy = 2, 1 is something, 0 is nothing).
frankly, BSP is very complex thing to understand and to implement, so i will recommend Box2D, especially because of lib ready and lot of docs/samples about this crossplatform lib around
just create something that's 1x,2x or 3x player width (from the next animation frame) and put the player mask inthere (1's) and add the enemy (also 1's)
when it's in that playerx-player.width to player+player.width boundery box to the map.
then all you need is a quick scan to see if there is a value equal to 2 which means a hit/collide (1 player + 1 enemy = 2, 1 is something, 0 is nothing).
All that is great stuff, but I don't think those features really apply to what I've got planned for my next app. But you never know. It certainly fuels my imagination.