pixel color

sterlingy

Active Member
Licensed User
Longtime User
Is it possible to get the color of a pixel on a bitmap, even if the bitmap is not visible?

~sterling
 

sterlingy

Active Member
Licensed User
Longtime User
Thanks Erel.

What would be the most efficient way (if there is one) to see if a specific colored pixel is within the bounds of a Rect's coordinates?

-Sterling
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
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.
 
Upvote 0

sterlingy

Active Member
Licensed User
Longtime User
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.

Maybe there is a better way?

-Sterling
 
Upvote 0

basil99

Active Member
Licensed User
Longtime User
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.

Maybe there is a better way?

-Sterling

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
 
Upvote 0

sterlingy

Active Member
Licensed User
Longtime User
Basil,

I realize this might be very efficient on the CPU, but what a nightmare to setup.

If your map is 8Kx8K, that would be 1,000,000 squares to place.

-Sterling
 
Upvote 0

basil99

Active Member
Licensed User
Longtime User
Basil,

I realize this might be very efficient on the CPU, but what a nightmare to setup.

If your map is 8Kx8K, that would be 1,000,000 squares to place.

-Sterling

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
 
Upvote 0

basil99

Active Member
Licensed User
Longtime User
and you can setup this array with some Windows utility, then simply add this "map" to project files and read on game start
 
Upvote 0

sterlingy

Active Member
Licensed User
Longtime User
Okay, 16x16 saves a lot, but that still over 250K Black and white blocks to place.

What Windows Utility do you have in mind?

-Sterling
 
Upvote 0

basil99

Active Member
Licensed User
Longtime User
Okay, 16x16 saves a lot, but that still over 250K Black and white blocks to place.

What Windows Utility do you have in mind?

-Sterling

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
 
Upvote 0

sterlingy

Active Member
Licensed User
Longtime User
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

Thanks Basil, I'll look into this.

-Sterling
 
Upvote 0

basil99

Active Member
Licensed User
Longtime User
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

Good luck ! Time to sleep in my country ) CU
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
there's no need for all those extra huge maps.

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).
 
Last edited:
Upvote 0

sterlingy

Active Member
Licensed User
Longtime User
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

Good luck ! Time to sleep in my country ) CU

I looked briefly at Box2D. Seems to have some promise. Not what I'm looking for, unless I missed something. It seems to just be a physics engine.

-Sterling
 
Upvote 0

sterlingy

Active Member
Licensed User
Longtime User
there's no need for all those extra huge maps.

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).

Sorex,

I'm a bit confused. What I gathered is that your concept is relatively simple, but I don't actually grasp the entire approach. Can you elaborate?

-Sterling :sign0085:
 
Upvote 0

basil99

Active Member
Licensed User
Longtime User
I looked briefly at Box2D. Seems to have some promise. Not what I'm looking for, unless I missed something. It seems to just be a physics engine.

-Sterling

Features of Box2D from JBox2D: A Java Physics Engine

•Rigid body physics
•Stable stacking
•Gravity
•Fast persistent contact solver
•Dynamic tree broadphase
•Sliding friction
•Boxes, circles, edges and polygons
•Several joint types: distance, revolute, prismatic, pulley, gear, mouse
•Motors
•Sleeping (removes motionless bodies from simulation until touched)

Continuous collision detection (accurate solving of fast bodies)

•Ray casts
•Sensors
•Serialization

and Sorex, please explain what you mean, i really don't catch this
 
Upvote 0

sterlingy

Active Member
Licensed User
Longtime User
Basil,

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.

-Sterling
 
Upvote 0
Top