Question

I am developing a small Android game. Before I started using AndEngine, I used the Canvas object and draw everything on it. For testing if two bitmaps collides with each other I checked if their bounding boxes overlap. In case of this, I checked if the overlapping rectangle of both bitmaps got one none transparent pixel in common. This method worked perfektly and I was able to detect pixel perfect collisions.

Because of some performance issues I started using AndEngine. Collision detection works quiet good but collision tests for two sprites definitly dosent work pixel perfect. The collision tests is "just" a bounding box test.

Was it helpful?

Solution

Here is a nice example of pixel perfect Detection,

AndEngine - Pixel Perfect Detection

OTHER TIPS

Below code for collision of two animated sprite works well for me in andEngine without using pixelPerfect class. It may help for you.

public boolean isCollides(AnimatedSprite animSprite1 ,AnimatedSprite animSprite2) throws Exception{


float diffX = Math.abs( (animSprite1.getX() +  animSprite1.getWidth()/2 )- 
             (animSprite2.getX() + animSprite2.getWidth()/2 ));
float diffY = Math.abs( (animSprite1.getY() +  animSprite1.getHeight()/2 )- 
             (animSprite2.getY() + animSprite2.getHeight()/2 ));

if(diffX < (animSprite1.getWidth()/2 + animSprite2.getWidth()/3) 
           && diffY < (animSprite1.getHeight()/2 + animSprite2.getHeight()/3)){

   return true;
}else
  return false;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top