Game Development Community

Mouse Input

by GilForumGuy · in Torque Game Builder · 01/19/2010 (6:11 pm) · 2 replies

Hello,

I am having trouble understand how to access the mouse object in torque script. I was looking through the Checkers game tutorial and there is a section on 'Checker Selection'.

Here is a piece of code from the example:

function SceneWindow2D::onMouseMove(%this, %modifier, %worldPos, %mouseClicks)
{
// set the position of the object that is designated to follow the mouse
$mouseObj.setPosition(%worldPos);
}


I am curious as to how to create/access the $mouseObj? The tutorial does not mention where this $mouseObj came from.

Thanks!


#1
01/20/2010 (12:53 am)
from the checkers tutorial:

$mouseObj = new t2dSceneObject() {sceneGraph = $checkersScene; };

"We then create a sceneObject stored in $mouseObj. You might have already guess that this will be an object that is positioned wherever the mouse goes, this will be utilized in the moving of our pieces. "

#2
01/22/2010 (2:32 pm)
Yeah, $ sign denotes a global variable which can be accessed across functions. So $mouseObj gets set, which creates the variable if it doesn't exist already and you can access it on future move commands.