LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: ziddia on October 09, 2011, 17:22:56

Title: Mouse Click
Post by: ziddia on October 09, 2011, 17:22:56
Hi,

I was just wondering how I could detect a mouse click on an entity (using the entity class in the Space Invaders game, just to help out with this example). I'm not new to Java, but I am to LWJGL and OpenGL. I know that you can use a method in the Mouse class to get co-ordinates and perform actions based on the co-ordinates clicked, but this would take a lot more work than just being able to determine when the entity is clicked on.

Thanks, and sorry if it's not clear enough... I tried  :/
Title: Re: Mouse Click
Post by: kappa on October 09, 2011, 17:27:55
have a read of the 5 Part LWJGL Basics Tutorials found on the wiki (http://www.lwjgl.org/wiki/index.php?title=Main_Page). Tutorial 2 of those should explain how to get mouse clicks.
Title: Re: Mouse Click
Post by: ziddia on October 09, 2011, 17:37:28
Thank you for such a quick response!

So, I already saw that, and I know what methods to use to get mouse input. But, I don't know how to use that with an entity class - only with getX and getY. I could find all the coordinates that the entity covers and use getX and getY to act upon a mouse click (if that makes sense? It does in my head...) but I was looking for an easier way.
Title: Re: Mouse Click
Post by: Evil-Devil on October 10, 2011, 07:38:27
You won't get away from the entity check that easily. Another approach you can try is color picking. That way you define a color for every entity you have and check the color that has been clicked on the specific location.
Title: Re: Mouse Click
Post by: ziddia on October 10, 2011, 14:00:15
Okay, thanks, I'll have a go at that.