Game Development Community

Enable Mouse Cursor

by Shawn Kennedy · in Torque 3D Professional · 12/07/2010 (2:42 pm) · 2 replies

I'm in the middle of doing some prototyping some GUI stuff for a project, and I can't seem to figure out how or where to enable the mouse cursor. I assume I can do it via script, but what I need to do, and in which script I need to do it are unknown to me at the moment.

Specifically, I'm working with a default, "Empty Room" project. I added some controls to the "playGui" and I would like to have the mouse cursor so I can interact with them, but when it gets into the "Empty Room level", the cursor disappears.

Any ideas? Any help is appreciated.

#1
12/07/2010 (7:44 pm)
You can use Canvas.cursorOn() and Canvas.cursorOff() in any client-side script to enable/disable the cursor. Where you might use these depends on how you want the player to enable/disable the cursor. In my case I have a key bound to toggling the cursor (M).

To accomplish this I have a function in scripts/client/default.bind.cs that looks like this:
function toggleMouseLook(%val)
{
   if(%val)
   {
      if(Canvas.isCursorOn())
         Canvas.CursorOff();
      else
         Canvas.CursorOn();
   }
}
And in the same file you can manually bind that to a key like this:
moveMap.bind(keyboard, "m", toggleMouseLook);
Or else add it to the bind list so players can choose their own key. In core/scripts/gui/optionsDlg.cs around line 400 you'll find a list of binds that look like the code below. Add this one anywhere inside that list (they'll be listed in that order in the options, so put it somewhere that seems appropriate):
$RemapName[$RemapCount] = "Toggle Cursor";
$RemapCmd[$RemapCount] = "toggleMouseLook";
$RemapCount++;

Make sure that wherever you put it is after the previous bind's "$RemapCount++;" (unless you're adding it as the first bind). You can then hit ctrl-o, go to controls, and should see "Toggle Cursor" in the list.

Note that you shouldn't do both (manually bind it in default.bind.cs and add it to the bind list).
#2
12/09/2010 (12:55 pm)
Thanks Henry, that solved my problem.