Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

you can use the pixmap.getPixel(x,y) function 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

example:

public static int pixelAtPoint(float x, float y, Pixmap pix) {
        int pixel = pix.getPixel(x,y);
        return pixel;
    }
share|improve this answer
    
Thanks. I will definitely try this one. At least now it makes sense, I used similar technique in XNA framework. –  Tom May 29 '13 at 5:09
    
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. –  Tom May 29 '13 at 5:15
    
if the texture is being drawn at point (100,100) on the screen, you can do something like pix.getPixel(x - 100,y-100); –  Ian Markowitz May 29 '13 at 5:29
    
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. :) –  Tom May 29 '13 at 19:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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