POSIX_ME_HARDER
POSIX_ME_HARDER

Reputation: 762

mouseListeners and JLabels using images with transparent pixels

I'm willing to make a isometric game but I'm having hard time with the mouseListener.

I'm using Swing and make losanges by using square images with transparent pixels (GIF format).

The problem is that making losanges touch each other edge means having the transparent pixels of one on the top of the others, which is a problem with the mouseListener.

I'm willing to know exactly which losange was clicked on, but as the transparent pixels of the nearby losange get on the top of the one that was clicked on, the wrong losange is selected as the KeyEvent source.

Is there a way to have mouseListener not considering transparent pixels as part of the shape ?

Thanks for reading.

Upvotes: 0

Views: 700

Answers (2)

Jason Nichols
Jason Nichols

Reputation: 11733

As mentioned by Jonathan, I think you're using the wrong technology for the job. I've had great success using a 2D graphics framework for software such as this. In my case I'm a big fan of Piccolo. I know you don't want to hear this, but consider starting over with the appropriate toolset.

Upvotes: 2

Jonathan Feinberg
Jonathan Feinberg

Reputation: 45324

It's not clear

1) why the tiles have to overlap, or

2) why you're using JLabels for the tiles

There's are many ways to solve the problem you're having, but I'd just make a single JComponent that renders the tiles as needed, and is the sole MouseListener.

Upvotes: 2

Related Questions