Pixel-perfect collision detection

Blitz3D Forums/Blitz3D Beginners Area/Pixel-perfect collision detection

CBass(Posted 2003) [#1]
Hello everybody,

which is the fastest way to implement pixel-perfect collision detection. ImagesCollide seems to be rather slow, but then again I doubt that I will be able to code some function that is faster and has the same functionality.
Pretesting with ImagesOverlap reduces the amount that I have to use ImagesCollide, but it's not always applicable.

To give a little example: You have got a little spaceship that flies through the screen, and the background is a painted level(one picture file). If the ship hits anything but the black part of the level picture you want it to collide.
Using ImagesCollide every time the ship moves works,but seems to be overkill. But how would you guys do this?


Perturbatio(Posted 2003) [#2]
I would make the background simply that, a background.
then implement a tile based map system to overlay.


CBass(Posted 2003) [#3]
So basically that means, that you have a background seperated into a bunch of tiles and you only do the ImagesCollide check if the spaceship is within a tile that has non-black background included?

Wouldn't you be able to tell a difference in execution speed then.(When the ship is close to non-black pixels...)

Excuse me, if I don't get the meaning of your reply right away, but I'm just starting with graphics programming...


Perturbatio(Posted 2003) [#4]
You can use imagesoverlap to test only the collidable areas, and then images collide for pixel perfection if they overlap.
(Rather than using one full screen image which will always overlap even if no collision test is required).

If you store the map tiles in an array then you can iterate through the array and determine when to bother checking for collisions.


Tiger(Posted 2003) [#5]
Imagecollide is firts checking if they are overlaping, if they do, its checking pixelperfect. So its waste of time to use overlap and then pixel perfect.
Because imagecollide do it for you.


CBass(Posted 2003) [#6]
All right, so using ImagesCollide for testing collidable areas would be the best way of having a pixel perfect collision detection. Are there any faster alternatives to ImagesCollide?


Perturbatio(Posted 2003) [#7]
well, in theory you could write a userlib to do it, but it would be complicated and may not be much faster (therefore not worth the effort).