This site requires JavaScript, please enable it in your browser!
Greenfoot back
Zamoht
Zamoht wrote ...

2013/12/1

Busch2207 pixel-perfect collision-detection

Zamoht Zamoht

2013/12/1

#
I have tried to make a slight modification for the Collision class from Busch2207's scenario Pixel-perfect collision detection. I want that the smaller object can be completely transparent and still check if the bounds of the smaller object is intersecting any pixel in the bigger object. I hope this makes sense. I tried to change the line for alpha detection: if(Ai.getColorAt(xi-x_Offset,yi-y_Offset).getAlpha()>0 && i.getColorAt(xi,yi).getAlpha()>0) to if(Ai.getColorAt(xi-x_Offset,yi-y_Offset).getAlpha()>0 && i.getColorAt(xi,yi).getAlpha()>=0) This kinda works but sometimes it'll return true even though the small transparent object is not intersecting the colored part of the big object. My objects are not rotated (I don't know if this makes any difference). Can someone help me modify the code?
danpost danpost

2013/12/1

#
This, 'i.getColorAt(xi,yi).getAlpha()>=0', should always return true.
Zamoht Zamoht

2013/12/1

#
Yeah but it would have worked if the frame of i wasn't equal to the hypotenuse of the original image. I ended up leaving the alpha detection as it was but added two lines to the method:
        a_small.getImage().setTransparency(255);
        i.drawImage(a_small.getImage(),i_hypot/2-a_small.getImage().getWidth()/2,i_hypot/2-a_small.getImage().getHeight()/2);
        a_small.getImage().setTransparency(0);
You need to login to post a reply.