I am trying to make something with java libgdx (2D). One thing that I can't figure it out is how to check mouse intersection with (fore example) isometric textures that are not rectangle shaped images. I found something about pickingColorPicking algorithm in libgdx, but I can't find any docs about how to use it. Any ideas?


You can use the pixmap.getPixel(x,y) method to find the color value at a certain pixel. To do collision checking, you could check the alpha value of that pixel. If it isn't zero, there is a collision.


public static int pixelAtPoint(float x, float y, Pixmap pix) {
    int pixel = pix.getPixel(x,y);
    return pixel;
  • \$\begingroup\$ Thanks. I will definitely try this one. At least now it makes sense, I used similar technique in XNA framework. \$\endgroup\$ – Tom May 29 '13 at 5:09
  • \$\begingroup\$ Can you explain me one more thing. If I am drawing few textures (in different positions) at the same moment and I want to check if mouse point intersects one of them - how should I check that? Because with pixelAtPoint I'm only checking position in specific texture point, not in the point of the screen, right? Sorry it's hard to understand what I'm asking. \$\endgroup\$ – Tom May 29 '13 at 5:15
  • \$\begingroup\$ if the texture is being drawn at point (100,100) on the screen, you can do something like pix.getPixel(x - 100,y-100); \$\endgroup\$ – Ian Markowitz May 29 '13 at 5:29
  • \$\begingroup\$ You're amazing, man! It works. I just needed to add this: if ((pixel & 0x000000ff) != 0) { // pixels collided } so that game would compare transparent .png and now it works fine. Cool! Many, many thanks to You. :) \$\endgroup\$ – Tom May 29 '13 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.