t2dstaticsprite and GUIMouseEventCtrl interaction
by C J · in Torque Game Builder · 11/22/2012 (6:36 am) · 4 replies
If I have a t2dstaticsprite located under a GUIMouseEventCtrl, what's the best way to pass mouse events on to the t2dstaticsprite in script?
About the author
#2
11/22/2012 (8:58 am)
www.garagegames.com/community/forums/viewthread/77998Quote:T2dSceneWindows already contain this method: t2dSceneWindow::getWorldPoint(x, y)
#3
You can set useMouseEvents to true on the static sprite, set class = "MyClickableSprite" or whatever you want to name that on it, then in script:
and your sprite is a button.
11/26/2012 (1:01 pm)
Or...You can set useMouseEvents to true on the static sprite, set class = "MyClickableSprite" or whatever you want to name that on it, then in script:
function MyClickableSprite::onMouseDown(%this)
{
// do some mouse stuff
}and your sprite is a button.
#4
And then somewhere in your scripts:
To make your clickable sprite say @@@ mouseDown every time you click it.
11/26/2012 (1:03 pm)
Sorry - for example, this object would be in your level file:new t2dStaticSprite() {
imageMap = "shipImageMap";
class = "Ship"; // so we can create a callback
frame = "0";
sourceRect = "0 0 0 0";
canSaveDynamicFields = "1";
Position = "11.225 0.910";
size = "32.000 32.000";
useMouseEvents = "1"; // to use mouse events with this object
LinkPoints = "0.007 -0.658 0.339 -0.594 0.501 -0.349 0.339 -0.113 0.000 -0.029 -0.354 -0.103 -0.501 -0.334 -0.331 -0.579";
mountID = "3";
};And then somewhere in your scripts:
function Ship::onMouseDown(%this)
{
echo(" @@@ mouseDown");
}To make your clickable sprite say @@@ mouseDown every time you click it.
Torque Owner Kevin James
Honestly, though, I'd be inclined to handle mouse events on the scenegraph and not the GUI. I don't even think there's documentation for the GUI