View Full Version : DelphiX Collision Detection by pixel metod.

27-11-2003, 11:59 AM
Hi...i am quite desperated about this...

Does anyone know some tutorial which shows how to detect the collision of two sprites but not by bounding box metod.
I know that every sprite has the CheckPixel property that can be setup to true if you want to detect collision by pixel checking. But it doesnt work at all;(

I will be very greatfull for showing me a simple code that do the job or showing me some tutorial or even showing me alternative metod of checking collision...

In one tutorial i readed that CheckPixel metod doesnt work for animate sprites...but in my case it doeasnt work at all..

Thank You for Your help,



27-11-2003, 07:40 PM
The second tutorial on my website has some collision procedures in it, which work pretty well. You might wanna have a looksee.

28-11-2003, 08:48 PM
The thing about pixel perfect collision detection is that it is so CPU intensive. If you were to check every object against every other object you would have an unplayable game. What I would suggest, and this is a common way of doing things, is to use bounding boxes for possible collision and when two bounding boxes overlap, use pixel perfect collision detection for the two colliding objects. That way, you will not need nearly as much processing but have pixel perfect collision detection. As for how to implement it, checkout Travellers' site. Otherwise let us know (me tired, must go bed now). As a sidenote, when you do do the pixelperfect bit, you may want to have a two dimensional array with the pixel masks preloaded into these, just another way of improving performance. There is another post regarding this on the forums so have a look around, sorry I don't know where it is.

02-12-2003, 05:30 PM
I know that Pixel checking metod is very CPU extensive...but sometimes you simply do not have a choice. Thank you for your advices and sugestions, i figured it by myself but thanks anyway.
I am browsing now the Traveler's website. The tutorials are great but i cant see any tutorial in one file that can be downloaded and then compiled under delphi. I need to copy all the code in to my project which is also slow operation under my Head CPU :lol: Perhaps Traveler has somewhere that file?
I know that You could say that i could browse ths tutorial to place where is described collision detection but at first look it looks simmilar to my own job which as i said before - do not work;( So i would like to compile all the tutorial and see how it works...maybe i have something wrong with my DelphiX?

Once again for Your help Guys!

take care


12-12-2003, 07:34 PM
Hi Wodzu... :)

of course the commonly used method for collision is good old Pythagorus.
This works very well for balls and can be used for irregular objects if an approximate center is nominated.

distance from 2 balls using their centers say B1(x,y) and B2(x,y)

X := B2x - B1x
Y := B2y - B1y

distance apart is sqrt( X*X + Y*Y)

collision distance is simply B1 radius + B2 radius....

Now this is great for small numbers of balls, (say up to 300), but other methods are needed for larger numbers of balls.. like sectors, or similar to pixel detection, one can have logical screen that stores
the x,y location of all sprites.. then you can search the intended new location of a sprite for the presence of others....... faster than pixel detection...

I have almost finished stage 1 of my collision program which I should put on the web before Xmas.. for the inspection of all interested...

it is written with delphi 5 and delphix

cheeeeeeeerrrrrrrrrrrsssssssssssss atozix