Sunday, March 18, 2012

Pixel Based Collision Detection:

Sometimes for the sake of efficiency you have to cheat a bit.
So, the question is... Do I take every-other pixel on the bounding box
of an object to see if it is colliding with the background? or do I only
take the pixels that make up the boarder?

Well, it depends on the size. Any square bitmap >=7x7 will be more
efficient using the boarder pixels only for collision detection.
Not only that, but we don't have to worry about diagonal 45 degree
pixels shooting through the object without getting detected... Ok...
It could still happen. Depends on the design of your game.


var boxWid:Number = 1;
var square:Number;
var halfDensity:Number = 0;
var boarderOnly:Number = 0;

do{
 boxWid++;
 square=boxWid*boxWid;
 halfDensity = square/2;
 boarderOnly = (boxWid-1)*4;
 
 if(boarderOnly < halfDensity){
  break;
 }
 
}while(true);

trace("boxWid===" + boxWid);


No comments:

Post a Comment