Mouse Click And Hold
by Scott Doerrfeld · in Torque Game Engine · 05/30/2007 (9:28 am) · 5 replies
I would like to differentiate between a mouse click and a mouse click-and-hold, where I can have an event happen after the mouse button is held for a certain time.
Is there a simple way to do this in the engine code?
Is there a simple way to do this in the engine code?
About the author
#2
The script logic is really simple, and I probably took some unnecessary logic steps, but you get the point. The high-res timer implementation is the hardest part, and that is a cake walk =).
05/30/2007 (9:48 am)
The simplest way I can think of is implementing a high resolution timer in the engine code, exposing the object in script, and then performing the logic within Torque Script:new TimerObject(mouseClickTimer)
{
type = 0;
};
function responseFunction(%val))
{
if(%val == true)
echo("Mouse held long enough");
else
echo("Mouse not held long enough");
}
function leftClickAction(%val)
{
if(%val)
{
mouseClickTimer.start();
}
else
{
%val = mouseClickTimer.getElapsed();
if(%val > 3) [b]// Picked an arbitrary value, 3 seconds[/b]
responseFunction(true);
else
responseFunction(false);
}
}
moveMap.bind(mouse, button0, leftClickAction);The script logic is really simple, and I probably took some unnecessary logic steps, but you get the point. The high-res timer implementation is the hardest part, and that is a cake walk =).
#3
05/30/2007 (11:00 am)
How do I make a high resolution timer in the engine?
#4
05/30/2007 (11:02 am)
I was hoping I could use SI_REPEAT for the mouse click the same way it is used when a key is held down.
#5
05/30/2007 (11:12 am)
Send me an e-mail to mperry@zombieshortbus.com. I'll send you the high resolution timer I built.
Torque Owner Scott Doerrfeld