Lemur mouse click with no target


#1

@pspeed Any way to register a mouse listener in lemur to be called if I click in the scene and don’t hit anything with a CursorEventControl? I want to de-select a ship part if someone just clicks a random part of the scene and there are no other ship parts under the cursor.


#2

If there are background elements to the scene then you can register a listener with some higher up node (even the root node). It will receive the events that none of the children do.

…it only works if there is geometry to click on, though. So for example, this approach probably wouldn’t work in outer space. I suspect it will be fine in your ship-building hangar, though.


#3

For my 2D top-down game, I created an invisible quad that extended the width and length of the scene used for playing and registered the listener on that.


#4

Yep, it’s the easiest way.

Maybe someday I will add a “miss” listener but it hasn’t been a high priority since these approaches work pretty well.


#5

That works great for 2D but if I did this in the 3D game I would have to use a background transparent billboard that constantly changes in size to accommodate the camera movement


#6

But you already have scene in the background, don’t you?


#7

@pspeed if I do that on the GUI node does the root node viewport get processed first?

EDIT: If so, I can copy your popup blocker code


#8

The order is configurable:

Default is GUI first:

But really, based on your video, you already have a background scene… it is probably already getting collisions. Just register a cursor event listener with the root node and see what you get. It’s the easiest way.


#9

I will face the same problem in space though. Using Lemur to select fleets in space so I figured I would solve the “un-select” problem centrally since I do entity selection in a reusable AppState


#10

Just remember that if you switch the order then your 3D scene will get clicks even when underneath some GUI element, button, etc…

Edit: and you may find that your skybox (I assume you have one) will get clicks on the 3D scene anyway.

Personally, I’d put a listener on the rootnode and see if it works or not before doing anything fancier.


#11

Good point. Crapnutz! I’ll just settle for the in the shipyard fix for now then.