Game Development Community

Toggle CursorOn via MouseUp/Down

by Darrel Cusey · in Torque Game Engine · 03/20/2006 (9:34 pm) · 3 replies

I am using Torque 1.4 HEAD

What I'm trying to do: I would like the cursor to be on when the right mouse button is up, and for it to be off when the cursor is down.

What's not working: Game seems to detect the right mouse up just fine, and turns the cursor on -- but once the cursor is on, it completely ignores the right mouse down so there's no way for me to turn the cursor off again.

I've searched through the forums and found some posts saying that onMouseUp and onMouseDown are _not_ processed by the game, and other posts saying that they _are_. Finney's books just tell me that it is possible to shift-click in the Torque GUI Editor, and TDN just lists the fact that there are cursorOn() and cursorOff() functions available to the console... so, no real help in any of those places.

This is the code I have:

function mouseFire(%val)
{
   $mvTriggerCount0++;
}

function altTrigger(%val)
{
   $mvTriggerCount1++;
      if (%val){
        //Button Down
        cursorOff(); 
      } else {
        //Button Up
        cursorOn();
      }
}

moveMap.bind( mouse, button0, mouseFire );
moveMap.bind( mouse, button1, altTrigger );

// I've tried binding button1 to the moveMap alone, the GlobalMap alone, and to both... but none
// of these seem to make any difference
// GlobalMap.bind( mouse, button1, altTrigger );


I have a sneaking suspicion that I'm missing something painfully obvious, but just can't seem to find it.

#1
03/21/2006 (12:06 am)
Use GlobalActionMap.bind( mouse, button1, altTrigger ); instead of moveMap.bind( mouse, button1, altTrigger ); for the RMB.
#2
03/21/2006 (1:25 am)
That GlobalActionMap is a good thing to know about. I was looking for a reason why the mouse buttons weren't responding for something else and this solved it. Plus now I have the cursor switch on right mouse button.
#3
03/21/2006 (4:45 pm)
That did the trick!

Thank you both very much. In the spirit of giving back to the community, what I was doing was trying to replicate the "standard" mouse control setup that you find in popular MMOs. I'm using Thomas' Advanced Camera resource, and this is the pertinent parts of my default.bind.cs:

function mouseFire(%val)
{
   $mvTriggerCount0++;
}

function altTrigger(%val)
{
   if (!$firstPerson) {
      if (%val){
        //Button Down
        cursorOff(); 
        ClientGroup.getObject(0).getCameraObject().setOrbitMode();
        moveMap.bind( mouse, xaxis, yaw );
        moveMap.bind( mouse, yaxis, pitch );
        moveMap.bind( mouse, zaxis, zoomCamera );
      } else {
        //Button Up
        cursorOn();
      }
   }  
}
function middleMouse(%val)
{
  if (!$firstPerson){
     if (%val){
        //Button Down
        cursorOff(); 
        ClientGroup.getObject(0).getCameraObject().setOrbitMode();
        moveMap.bind( mouse, xaxis, rotateCameraHorizontal);
        moveMap.bind( mouse, yaxis, rotateCameraVertical );
        moveMap.bind( mouse, zaxis, zoomCamera );
      } else {
        //Button Up
        cursorOn();
      }
  } 
}

moveMap.bind( mouse, button0, mouseFire );
GlobalActionMap.bind( mouse, button1, altTrigger );
GlobalActionMap.bind( mouse, button2, middleMouse );

...and it works perfectly - so, again, thank you both for pointing that out :-)