Mouse Click

Started by ziddia, October 09, 2011, 17:22:56

Previous topic - Next topic

ziddia

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  :/

kappa

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.

ziddia

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.

Evil-Devil

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.

ziddia

Okay, thanks, I'll have a go at that.