Mouse Input information

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
UpandComing
Posts: 5
Joined: Tue Dec 06, 2011 3:12 pm

Mouse Input information

Post by UpandComing »

I know that generally the Irrlicht engine is tailored to 3D but it does have 2d capabilities and since I'm using this as an engine learning exercise then I believe I can be forgiven for under-using it. Anyway's... I'm fairly new to games programming, well programming in particular but if I do say so myself i've got the C++ language down.... The basics anyway's. My dilemma is that I'm not sure where to start when it comes to mouse click events in 2d. Lets take for example the Solitaire application that comes with Windows. I can't think how the mouse input can be reverse engineered. I thought at first after coming across a small forum post on axis aligned bounding boxes when browsing through OpenGL posts that i'd found my answer. But alas, it seems like I had misunderstood aabbs. So here I am, looking to see if any kind and knowledgeable programmer could shed some light on this, i'm not looking for code example just some explanations or theories on how i could possibly accomplish this. After all the best way to learn is to research, try and fail, then try some more. In my own personal experience anyway's =]

Thanks in advance.

edit: Where I say mouse click events in 2d I simply mean the example functionality of the Solitaire example. I'm fully aware of how to derive the IEventReceiver and its OnEvent function. I've even implemented a mouse click that reveals a single card on the screen but it's revealed where ever the mouse is clicked rather than just over the cards texture area. I theorized that maybe I could compare the mouses X and Y position to match the position of the textured area on screen but that would mean overloading operators to implement this. I was wondering if there was a simpler way or even just others.

Again, thanks in advance
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Mouse Input information

Post by serengeor »

In solitaire you would simply check if your mouse cursors position is inside of one of the cards bounding rectangle. So basically you have to know all rectangles of the cards and check which one the mouse is in when you click it. I think it is possible just to get a gui element which was clicked if you're using them.
Working on game: Marrbles (Currently stopped).
docWild
Posts: 38
Joined: Wed Nov 30, 2011 4:29 pm

Re: Mouse Input information

Post by docWild »

By declaring your card to be an IGUIImage it would then have access to all the IGUIElement methods (such as getRelativePosition()).
shadowghost21
Posts: 56
Joined: Wed Nov 23, 2011 11:53 pm

Re: Mouse Input information

Post by shadowghost21 »

You could also make invisible buttons on top of each of the cards then you would get access to the event processing. You get events for when the mouse enters and exits a gui element.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Mouse Input information

Post by serengeor »

Theres no need for extra button gui elements if you have image gui element, then you check for mouse click and check which element is hovered. Or use buttons with images instead of image elements.
Working on game: Marrbles (Currently stopped).
shadowghost21
Posts: 56
Joined: Wed Nov 23, 2011 11:53 pm

Re: Mouse Input information

Post by shadowghost21 »

Thanks for correcting me I wasn't entirely sure the gui images would do it too as I haven't tried yet. I was bust playing cities XL to try :)
Post Reply