I created an image and added to the imagelayer as I get the click event with this picture? Using the pointer it returns only the value of x and y that was clicked. I want to identify which was clicked on the image, as I do that?
Asked
Active
Viewed 284 times
1 Answers
1
Your question is not totally clear, but I believe you're asking if you can listen for click events directly on a layer, and you can:
ImageLayer layer = ...
layer.addListener(new Pointer.Adapter() {
public void onPointerStart(Pointer.Event event) {
// event.localX() and event.localY() are the mouse position in the layer's
// coordinate system; event.x() and event.y() are the mouse position
// in screen coordinates
}
});
It appears from the comments that you want to test whether a pixel is transparent in an image, and you want an example. Here you go:
Image image = ...;
int[] argb = new int[1];
// this will copy the ARGB value of the pixel at x y into the argb array
image.getRgb(x, y, 1, 1, argb, 0, 1);
// this will extract the alpha value from the pixel
int alpha = (argb[0] >> 24) & 0xFF;

samskivert
- 3,694
- 20
- 22
-
Sounds like @GFM wants to correlate the link with a subregion of the image, in which case you'd want define a region (say as a rectangle, circle, or polygon), then test whether the event.coordinates fell inside one of those area. This could be done inside the listener callback `onPointerStart` above. For more robust examples, see the PlayN samples. – klenwell May 08 '12 at 05:09
-
ImageLayer not have this method addListener(); – Greg May 09 '12 at 16:43
-
I'm doing a play, put three pictures on the screen and want to identify when the User click on any of them. using event.localX () it will return me an X but how do I know if this X is inside the image? – Greg May 09 '12 at 16:44
-
If you mean whether the coordinate hits a non-transparent pixel, you'll have to use the latest trunk (or wait for the next release) which adds Image.getRgb, which can be used to check pixels. – samskivert May 10 '12 at 18:02
-
samskivert, can show me an example? Already tried the examples playn and have not found.. – Greg May 14 '12 at 12:14
-
I added an example to the answer. – samskivert May 14 '12 at 17:06
-
samskivert, I think you do not understood me. I have 3 imagelayers on my screen. imagelayer each have an image. these two images are equal. How do I identify which image is the different? – Greg May 15 '12 at 01:56
-
Add a listener to each of your layers and the listener that gets the event will be the layer that was clicked. I don't know how to explain it any more clearly. – samskivert May 15 '12 at 18:23