Game Development Community

Right Click Mouse Aim with bindCmd

by David Thompson [Smatisfaction] · in Torque Game Engine · 07/10/2007 (12:39 am) · 5 replies

I am having trouble using the bindCmd to do what I want. First a little background. My game will primarily be a game where the user is clicking buttons on a HUD/interface. As a result, the mouse cursor will always be visible, through a call to "CursorOn();" However, I want to make it so that the user, while moving (WASD), can switch to a mouse aiming by right clicking the mouse. This lets the user simply hold down "W" (forward) while steering by moving the mouse. I want this mouse steering to last ONLY while the right mouse button is held.
I am building this off of the default, tutorial.base application, so the default behavior of mouse aiming/steering is already there when the cursor is not enabled. The cursor is by default on. The problem occurs with the keymap


moveMap.bindcmd( mouse, button1, "CursorOff();", "CursorOn();" );

What I mean for this to do, is turn off the cursor (and by that, enable mouse aiming) when the right mouse button is held. Then, upon releasing the right mouse button, I want the cursor to reappear.

The second half works fine. I have a single button to turn the cursor on and off, so I have tested it. With the cursor off, if I right click, when I release, the cursor appears. However, if the cursor is enabled, right clicking (and holding) does NOTHING to make the cursor disappear. Why does my right click not process the first part of my bindCmd? Can anyone tell me how to make the cursor disappear on a right click, and then reappear upon release?

Thank you for your help.

#1
07/10/2007 (10:59 am)
I still need help, but I am able to provide a little bit more insight.
I think the problem is that the cursor cannot be turned off, WHILE the mouse is doing something. I think that the CursorOff(); call cannot be executed because the mouse is busy processing other information (the fact that the right mouse button is being held down). This doesn't seem to be very convenient, so I'm sure there is a workaroud for this, if anyone knows it, I would greatly appreciate that. Also, please correct me if my assumption is wrong.
#2
07/10/2007 (11:15 am)
If your using %val if %val == true then you have the button pressed and when it is false you have released it. And I don't know if this will work like your saying but...

something like:
function myButton(%val)
{
if (%val)
{
echo("mouse pressed")
}
else
{
echo("mouse released")
}
}
#3
07/10/2007 (1:15 pm)
Yeah, I have tried something of that structure before, thinking it would do the job. What you just described would work for things like echo, which is really weird. However, if instead of " echo("mouse pressed") " I would put " cursorOff(); ", it mysteriously doesn't do anything.

I found this somewhere on the site, and think it may be the problem.

"cursorOff()-Sets the cursor inactive: mouse events (clicks, moving, and dragging) are not registered by the controls on the canvas."

I think something in there is causing it so that I cannot turn the cursor off WHILE using the mouse. I haven't yet found a way to make holding the mouse button down, get rid of the mouse cursor. Releasing the mouse will always make the cursor appear however.
#4
07/10/2007 (1:28 pm)
Have a look here this might work for what your doing.
#5
07/11/2007 (10:54 am)
Sorry, it doesn't seem like that is related really. I think that is a problem that they actually fixed in later versions (I am using 1.5.2).

Basically, what it boils down to, is that THIS works

moveMap.bindcmd(keyboard, m, "cursorOff();", "cursorOn();" );
---------------------------------------------------------------------------------------
but this DOESN'T

moveMap.bindcmd(mouse, button1, "cursorOff();", "cursorOn();" );



Only the on release part works for the mouse version, the on press part (cursorOff) does nothing for the mouse version, although it works fine for the keyboard. Is this a bug, or am I missing something really obvious?