Game Development Community

Recomended method of Mouse Movement

by Greg Squire · in Torque Game Builder · 01/10/2007 (5:43 pm) · 2 replies

In becoming more familiar with TGB, it appears there are two ways to deal with the mouse


First is via mouse events in the SceneWindow2D object (such as)



function SceneWindow2D::onMouseMove(%this, %mod, %worldPosition)
{
%this.mouseMoveShip(%mod, %worldPosition);
}

function sceneWindow2D::onMouseDragged(%this, %modifier, %worldPosition, %mouseClicks)
{
%this.mouseMoveShip(%mod, %worldPosition);
}

function sceneWindow2D::onMouseDown(%this, %mod, %worldPosition, %mouseClicks)
{
$pShip.isFiring();
}

Or via the bind and bindCmd handlers (such as)

playerMap.bindCmd(mouse, button0, "playerFire();", "playerFireStop();");
playerMap.bind( mouse, "yaxis", handleMouseY );
playerMap.bind( mouse, "xaxis", handleMouseX);


I'm developing a full screen shooter that will use the mouse to control the ship (cursor will be turn off in game and back on when in menus). So, I'm wondering what's the recommended method to use (the one that might give me less grief perhaps). Ideas?

#1
01/11/2007 (8:15 am)
The first thing to remember is that those sceneWindow mouse methods can also be used on objects (as long as you enable that), which makes using normal objects (instead of GUI stuff) as buttons very easy. I've never used bind with the mouse, so I guess that's not the best way - but it might be the easier way with the mouse buttons. You can poll the mouse position directly anyway, so you don't really have to use the events if you have a specific goal in mind.

I'd recommend activating useObjectMouseEvents and then turning on useMouseEvents on the menu buttons and stuff - and then just using that to make the menu.

Hope that made sense - I can ramble more about specifics if you'd like.
#2
01/22/2007 (4:18 pm)
I would agree with what Tom said.

The Scene Window mouse callbacks are ideal for most situations... with the bind commands being an option in case that sort of input is preferred. If you are unsure then just go with the Scene Window callbacks :)