Mouse Binding Problems
by MrPhil (Philip Ludington) · in Torque Game Builder · 02/27/2005 (11:04 pm) · 23 replies
So its 1:55 AM and I'm going to bed. Hopefully someone can solve my problem while I rest and I'm might have missed something obvious (tired) and if so I apologize. Here's my code and only the handleMouseWheel event seems to be working!?!? Did I get the names of the other events wrong? (Where is that info. anyway? I had to scratch through the forums for a while to find all these.)
Edit: Fixed a bunch of typos in the code.
// Create a new action map.
new ActionMap(playerMap);
// Bind keys to actions.
playerMap.bind( mouse, "zaxis", handleMouseWheel );
playerMap.bind( mouse, "yaxis", handleMouseY );
playerMap.bind( mouse, "xaxis", handleMouseX );
playerMap.bindCmd( mouse, "button0", "handleMousePickDown();", "handleMousePickUp();" );
// Activate the action map.
playerMap.push();
echo( "setupT2DScene complete." );
}
function handleMouseWheel( %val )
{
echo( "MouseWheel" SPC %val );
}
function handleMouseY( %val )
{
echo( "MouseY" SPC %val );
$MouseY = %val;
}
function handleMouseX( %val )
{
echo( "MouseX" SPC %val );
$MouseX = %val;
}
function handleMousePickDown()
{
%position = $MouseX SPC $MouseY;
echo( %position );
}Edit: Fixed a bunch of typos in the code.
About the author
My name is Philip Ludington, I'm a professional programmer by day and I dabble in game development by night. Learn more about my projects at www.MrPhilGames.com
#22
Thanks so much for the code! Exactly what I've been trying to do for a while, unsuccessfully, and you're the first to provide a solution.
One thing though. I start the game by pushing the run arrow button in TGB. And even though I move the mouse in tiny small increments, I get starting values like:
XAXIS: -537
YAXIS: -485
YAXIS: 1
XAXIS: 1
(similar small values from here on out)
My guess is that the mouse is being re-centered in the middle of the screen each frame, but this re-centering does NOT happen before the first xaxis and yaxis values are spit out. How can I avoid this initial jump? I tried adding this to your code:
sceneWindow2D.setMousePosition("0 0");
but it didnt' help. Suggestions? (This is 1.1.1 on a Mac.)
09/04/2006 (11:07 pm)
Edward --Thanks so much for the code! Exactly what I've been trying to do for a while, unsuccessfully, and you're the first to provide a solution.
One thing though. I start the game by pushing the run arrow button in TGB. And even though I move the mouse in tiny small increments, I get starting values like:
XAXIS: -537
YAXIS: -485
YAXIS: 1
XAXIS: 1
(similar small values from here on out)
My guess is that the mouse is being re-centered in the middle of the screen each frame, but this re-centering does NOT happen before the first xaxis and yaxis values are spit out. How can I avoid this initial jump? I tried adding this to your code:
sceneWindow2D.setMousePosition("0 0");
but it didnt' help. Suggestions? (This is 1.1.1 on a Mac.)
#23
Hi. You're welcome, although I think the folks who have been posting on the GPGT forum are going to get mad at me soon for helping elswhere when I should be responding to their posts. :|
I've been thinking about the problem you're experiencing and haven't come up with any reasons why you are seeing this behavior.
Be aware, this kind of mouse movement [tracking] is not relative to any cursor position, so you don't need to move the cursor back to <0,0>. Also be aware, that the mouse only gives inputs that are positive or negative, but not zero. i.e. With a mouse ( and bind() ) there is no 'break' concept.
As to why you would be seeing such large (in magnitude) values ... I'm stumped, especially if your mouse works for other apps just fine.
I think you're going to need to instrument the C++ code to figure this one out. Sorry I can't be of more help here.
Hall Of Worlds - For Gamers
EdM|GPGT
09/05/2006 (5:39 pm)
@VernHi. You're welcome, although I think the folks who have been posting on the GPGT forum are going to get mad at me soon for helping elswhere when I should be responding to their posts. :|
I've been thinking about the problem you're experiencing and haven't come up with any reasons why you are seeing this behavior.
Be aware, this kind of mouse movement [tracking] is not relative to any cursor position, so you don't need to move the cursor back to <0,0>. Also be aware, that the mouse only gives inputs that are positive or negative, but not zero. i.e. With a mouse ( and bind() ) there is no 'break' concept.
As to why you would be seeing such large (in magnitude) values ... I'm stumped, especially if your mouse works for other apps just fine.
I think you're going to need to instrument the C++ code to figure this one out. Sorry I can't be of more help here.
Hall Of Worlds - For GamersEdM|GPGT
Torque Owner Pavel Tovarys
Default Studio Name