How to make a popup menu show beside the mouse when it right-click?

It seems like most software do, mouse right click, show a popup menu beside the mouse.
I can show a Text object when mouse click, but it allways show at the same place,
how to let this object show at the place where mouse on screen?
Thanks all.

python would be the way to go here im not sure how advanced you are with bge…but the way I would do it is have an invisible plane on an overlay scene…then have a mouseoveranysensor that uses a property that you assign to the plane…then have your text popup at the mouoverany.hitposition when you want…it will appear at that spot on the invisible plane…some python will be required i think.

What superflip said can be used as a basis, assuming you have an overlay scene and you’re not wondering about some kind of 3D floating window.

Your menu can be a bunch of buttons with mouseover (nowadays called mouse focus) sensors that have logic set up to do what they do like regular buttons. Parent them to an empty object and use python to move the empty object to the mousefocus.hitposition.

# attach to the object that has the mouse sensors connected
# connect to mouse sensor (right click) and enable true level triggering and tap mode
# name your mouse focus sensor "mouseover"
# add a boolean property to the object called "popupVisible" and set it to false
# name the empty you parented your popup buttons to "PopupMenu"

import bge

cont = bge.logic.getCurrentController()
menu = cont.owner.scene.objects["PopupMenu"]
mouseover = cont.sensors["mouseover"]

def ShowPopup():
    if mouseover.positive:
        hitpos = mouseover.hitPosition
        menu.worldPosition = hitpos

def HidePopup():
    menu.worldPosition = [100,100,100] #somewhere that is not seen

if not own["popupVisible"]:

#toggles the value so next time it'll do the opposite
own["popupVisible"] = not own["popupVisible"]

Untested :stuck_out_tongue:

Thank you very much, I tryed it, but I don’t know why it not work. Please see the picture:

Here i tried to make as simple of an example that I can make…Notice the small script is run in the overlay scene…And you must be looking through the camera for overlay scene stuff to work. It just adds text and puts it where you click. See if you can pick it apart. Its not too difficult once you grasp it.

And to make more lines you just use
within your text string to go to a new line.


overlay_menu.blend (457 KB)

Thank you very much, It works!
Maybe I’ll rebuild the menu with some buttons, let player can choose one.