Game Development Community

onMouseDown Help! [Resolved]

by Neal Guzman · in Torque Game Builder · 06/21/2011 (10:38 am) · 25 replies

I have tried and doesn't work.
I feel I'm missing something important somewhere.

What I'm trying to do is to get the mouse button to fire a bullet.

In this case the bullet is a clone of the actual bullet.

shoot works fine with keybinds.

keys.bindCMD("keyboard","space","shoot();","stopshoot();");



In Game.cs
in the startgame function

// Add these two lines
   Canvas.hideCursor();
   sceneWindow2D.setUseWindowMouseEvents(true);



function SceneWindow2D::onMouseDown(%this)
{
shoot();
}

Which should go to the shoot function

function shoot()
{

%currentclone = pbullet.clone(1);

%currentclone.setposition(player.getposition());

%currentclone.setlinearvelocityX(100);

}

About the author

I am an GUI Artist, HUD Artist, Texture Artist, GUI Editor, and Programmer and Game Designer/Developer. I know and still am learning c# and torque script. I earned my Bachelors' of Science in Game Design and Development on 12/16/11

Page«First 1 2 Next»
#21
07/30/2014 (11:36 am)
It isn't hard. I worked perfectly for me, otherwise I wouldn't have suggested it....

It should echo to the log when you click anywhere in the window.

Is HUD2 a full-screen GUI? If so, is it set to use mouse events? If it isn't it may be blocking your mouse clicks from reaching the window object behind it.
#22
07/30/2014 (12:17 pm)
That's what it was and i had to change it from sceneWindow2D to

function t2dSceneWindow::onMouseDown(%this, %a, %b, %c)
{
echo(" -- onMouseDown " @ %a @ " " @ %b @ " " @ %c);
shoot();
}

then it worked. I feel really stupid 3 years to figure this out and all I had to do was enable the hud2 with the t2dscenewindow.

Kudos,
#23
07/30/2014 (12:38 pm)
Sweet - now I suppose one of us should track down the parameter names on that callback, but the %b parameter appears to be the world coordinate of the click ("x y" pair). Extract the info like so:
%xCoord = getWord(%b, 0);
%yCoord = getWord(%b, 1);
And I see the issue with the name - sceneWindow2D assumes that the t2dSceneWindow object was named "sceneWindow2D". Defining the callback on t2dSceneWindow means that if you have more than one scene window the same callback fires for all of them - probably not an issue....
#24
07/30/2014 (4:08 pm)
-- onMouseDown 0 343.000000 277.000000 1

is what shows up in my log window.

#25
07/31/2014 (12:01 pm)
Yup, what you're seeing is the three callback variables spewed to the console - %a is 0, %b is (343.000000 277.000000) and %c is 1.
Try this:
function t2dSceneWindow::onMouseDown(%this, %a, %b, %c) 
{ 
    echo(" -- onMouseDown a:" @ %a @ "  b:" @ %b @ "  c:" @ %c); 
}
you should see
-- onMouseDown a:0  b:343.000000 277.000000  c:1
So, this code will get the x and y values of the click coordinate (if you need them):
function t2dSceneWindow::onMouseDown(%this, %a, %b, %c) 
{ 
    echo(" -- onMouseDown a:" @ %a @ "  b:" @ %b @ "  c:" @ %c); 
    %xCoord = getWord(%b, 0);  
    %yCoord = getWord(%b, 1);
}
#26
08/01/2014 (7:30 am)
-- onMouseDown a:0 b:365.000000 248.000000 c:1

very clever

Page«First 1 2 Next»