Ok i have designed a cool way of controlling my ship but i will need some output (text on the screen) to help me tweak it to make it realistic. So i need to first of all get my mouse coordnintes on the screen. I have put this line of code into my code:
okay… and the aspect2d coordinate space is -1 to 1 on both axes? If so, I’m not seeing anything flagrantly wrong with that line in particular.
You might try a simple print statement to verify that execution is even reaching the textObject declaration (and if that’s in a loop, you’re going to want to reconsider how you set it up, otherwise you’re going to have a zillion rogue textNodes building up in the scene over time).
Well, if you can verify that it’s getting to the point right before the if statement, and it’s not executing anything in the if statement, than the if condition is failing. If that’s the case, I’ve never used mouseWatcherNode much, but I’d guess there’s something you need to do to prime/initialize/enable it if it’s not detecting your mouse by default.
The text is never created because hasMouse() returns False, i.e. the mouse is not found within the frame.
What you should be doing is listening for mouse movement, and then destroy() and create a new text overlay every time the mouse X position changes.
EDIT: Here’s some code that might help…
from pandac.PandaModules import *
from direct.gui.OnscreenText import OnscreenText
from direct.task import Task
hasMouse = False
lastX = 0
lastY = 0
text = None
font = loader.loadFont("cmss12")
def mouseMoved(x, y):
updateText('Mouse X position: %g' % x)
if text is not None:
text = OnscreenText(text=msg, style=1, font=font,
fg=(0,0,0,1), align=TextNode.ALeft, pos=(-1.15, .8), scale=.07)
#Task to move the camera
global lastX, lastY, hasMouse
hasMouse = True
x = base.mouseWatcherNode.getMouseX()
y = base.mouseWatcherNode.getMouseY()
if x!=lastX or y!=lastY:
lastX = x
lastY = y
hasMouse = False