Getting the mouse to work?
by Gellyware · in Torque Game Builder · 09/09/2006 (6:03 pm) · 9 replies
I've tried placing this in the game.cs
//accept mouse input for this game
sceneWindow2D.setUseWindowMouseEvents(true);
and then in one of my scripts:
function sceneWindow2D::onMouseDown(%this,%modifier,%worldPosition,%mouseClicks)
{
echo("MOUSE IS DOWN" @ getRandom(0, 1000) );
%sg = sceneWindow2D.getSceneGraph();
%objects = %sg.pickPoint(%worldPosition);
%objCount = getWordCount(%objects);
for(%i=0;%i<%objCount;%i++)
{
%obj = getWord(%objects, %i);
if (isObject(%obj))
{
if (%obj.class $= "coin")
{
echo("coin selected");
%obj.setPositionY( %obj.getPositionY()-5 );
}
}
}
}
Is there something that I'm doing wrong? How do you allow for the mouse to select an object?
//accept mouse input for this game
sceneWindow2D.setUseWindowMouseEvents(true);
and then in one of my scripts:
function sceneWindow2D::onMouseDown(%this,%modifier,%worldPosition,%mouseClicks)
{
echo("MOUSE IS DOWN" @ getRandom(0, 1000) );
%sg = sceneWindow2D.getSceneGraph();
%objects = %sg.pickPoint(%worldPosition);
%objCount = getWordCount(%objects);
for(%i=0;%i<%objCount;%i++)
{
%obj = getWord(%objects, %i);
if (isObject(%obj))
{
if (%obj.class $= "coin")
{
echo("coin selected");
%obj.setPositionY( %obj.getPositionY()-5 );
}
}
}
}
Is there something that I'm doing wrong? How do you allow for the mouse to select an object?
About the author
#2
It seems that when you push a Dialogue that the gui being pushed becomes the main focus and anything 'under' it isn't affected by mouseclicks.
What is the solution?
Use the mainScreenGui as the debugger gui and just leave the default:
Canvas.setContent(mainScreenGui);
Hope this helps someone.
09/10/2006 (12:36 am)
Given enough time, anyone can solve their own problems :)It seems that when you push a Dialogue that the gui being pushed becomes the main focus and anything 'under' it isn't affected by mouseclicks.
What is the solution?
Use the mainScreenGui as the debugger gui and just leave the default:
Canvas.setContent(mainScreenGui);
Hope this helps someone.
#3
It seems that when you push a Dialogue that the gui being pushed becomes the main focus and anything 'under' it isn't affected by mouseclicks.
What is the solution?
Use the mainScreenGui as the debugger gui and just leave the default:
Canvas.setContent(mainScreenGui);
Hope this helps someone.
09/10/2006 (12:40 am)
Given enough time, anyone can solve their own problems :)It seems that when you push a Dialogue that the gui being pushed becomes the main focus and anything 'under' it isn't affected by mouseclicks.
What is the solution?
Use the mainScreenGui as the debugger gui and just leave the default:
Canvas.setContent(mainScreenGui);
Hope this helps someone.
#4
It seems that when you push a Dialogue that the gui being pushed becomes the main focus and anything 'under' it isn't affected by mouseclicks.
What is the solution?
Use the mainScreenGui as the debugger gui and just leave the default:
Canvas.setContent(mainScreenGui);
Hope this helps someone.
09/10/2006 (1:11 am)
Given enough time, anyone can solve their own problems :)It seems that when you push a Dialogue that the gui being pushed becomes the main focus and anything 'under' it isn't affected by mouseclicks.
What is the solution?
Use the mainScreenGui as the debugger gui and just leave the default:
Canvas.setContent(mainScreenGui);
Hope this helps someone.
#6
09/10/2006 (6:18 am)
That'd be simpler than you might think. :)onRightMouseDown(%this, %modifier, %worldPosition, %clicks) onRightMouseDragged(%this, %modifier, %worldPosition, %clicks) onRightMouseUp(%this, %modifier, %worldPosition, %clicks):p
#7
09/10/2006 (11:26 am)
Thanks Teck :)
#8
I'm using an unmodified version of TGB on OSX. Help->About in the Level Builder reports Torque2D Version: v1.1.0, and Torge Game Builder Version: v1.0.0.
I am using the same scripting structure of the Scroller Demo tutorial.
I want mouse button0 down and up callbacks. I do not want or care about callbacks for a mouse button click over any specific on-screen object. A click anywhere is fine.
Here's the snippet of code. What am I missing?
Everything works with the keyboard as I expected, but createMissile() is not being called on any button press of the mouse.
Any ideas?
09/10/2006 (12:02 pm)
I'm having mouse troubles too.I'm using an unmodified version of TGB on OSX. Help->About in the Level Builder reports Torque2D Version: v1.1.0, and Torge Game Builder Version: v1.0.0.
I am using the same scripting structure of the Scroller Demo tutorial.
I want mouse button0 down and up callbacks. I do not want or care about callbacks for a mouse button click over any specific on-screen object. A click anywhere is fine.
Here's the snippet of code. What am I missing?
moveMap.bindCmd(keyboard, "up", "pShipUp();", "pShipUpStop();"); moveMap.bindCmd(keyboard, "down", "pShipDown();", "pShipDownStop();"); moveMap.bindCmd(keyboard, "left", "pShipLeft();", "pShipLeftStop();"); moveMap.bindCmd(keyboard, "right", "pShipRight();", "pShipRightStop();"); $pref::Input::MouseEnabled = 1; enableMouse(); moveMap.bindCmd(keyboard, "space", "$pShip.createMissile();", ""); moveMap.bindCmd(mouse0, "button0", "$pShip.createMissile();", "");
Everything works with the keyboard as I expected, but createMissile() is not being called on any button press of the mouse.
Any ideas?
#9
sceneWindow2D.setUseWindowMouseEvents(true);
I haven't tried binding the mouse yet, but it seems that you 'must' enable mouse events for TGB to begin looking for them.
09/10/2006 (2:35 pm)
Maybe try adding this in your game.cs:sceneWindow2D.setUseWindowMouseEvents(true);
I haven't tried binding the mouse yet, but it seems that you 'must' enable mouse events for TGB to begin looking for them.
Torque Owner Gellyware
canvas.pushDialog(DebugGui);
This seems to be BLOCKING my mouse events. I've tried resizing the debugGui but that doesn't help.
Any suggestions would be appreciated!
If I comment out the debugGui push dialogue then the mouse events work.