Hello Guest

Mouse Click

  • 4 Replies
  • 9615 Views
Mouse Click
« 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  :/

*

Offline kappa

  • *****
  • 1316
Re: Mouse Click
« Reply #1 on: October 09, 2011, 17:27:55 »
have a read of the 5 Part LWJGL Basics Tutorials found on the wiki. Tutorial 2 of those should explain how to get mouse clicks.

Re: Mouse Click
« Reply #2 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.

Re: Mouse Click
« Reply #3 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.

Re: Mouse Click
« Reply #4 on: October 10, 2011, 14:00:15 »
Okay, thanks, I'll have a go at that.