Need to cancel or restrict behavior mouse events?
by Alex Rice · in Torque Game Builder · 09/16/2008 (8:00 pm) · 2 replies
Greetings everyone. I am working with the behaviors system in TGB 1.7.4 and it looks incredibly powerful. It is really going to help my scripting a lot.
Question: is there is a way to suppress behavior mouse events? For example onMouseDragged gets sent to every sprite underneath the mouse, that has the behavior. In my level this behavior fires for 28 sprites instead of the 1 sprite on top, which is only what I want it to fire for :-(
function MyBehavior::onBehaviorAdd(%this)
{
%this.owner.setUseMouseEvents(true);
}
function MyBehavior::onMouseDragged(%this, %nModifier, %vec2WorldPos, %nClicks)
{
%this.owner.setPositionX(%vec2WorldPos.x);
%this.owner.setPositionY(%vec2WorldPos.y);
warn("onMouseDragged" SPC %this.owner); // yikes we are dragging every sprite under the mouse!
}
I have instead used global variable and set the object id of what is being dragged, to limit the dragging behavior to a single object per drag. It works, however that seems like a poor solution: my Javascripting experience is it's a poor design to use global variables a lot, because of variable scoping and the penalty associated with it. Is Torquescript is similar in that respect?
I have studied MouseDraggableBehavior from the BehaviorPlayground project, however it's kind of confusing. It's illustrating several things actually- snapping to the mouse position, and to provide a sticky drag behavior. It does not use a global variable, but also calls setMouseLocked() and schedule()- why? I honestly don't understand what it's doing there.
Oops I guess that is three questions. Thanks in advance for your Torquescript wisdom.
Alex
Question: is there is a way to suppress behavior mouse events? For example onMouseDragged gets sent to every sprite underneath the mouse, that has the behavior. In my level this behavior fires for 28 sprites instead of the 1 sprite on top, which is only what I want it to fire for :-(
function MyBehavior::onBehaviorAdd(%this)
{
%this.owner.setUseMouseEvents(true);
}
function MyBehavior::onMouseDragged(%this, %nModifier, %vec2WorldPos, %nClicks)
{
%this.owner.setPositionX(%vec2WorldPos.x);
%this.owner.setPositionY(%vec2WorldPos.y);
warn("onMouseDragged" SPC %this.owner); // yikes we are dragging every sprite under the mouse!
}
I have instead used global variable and set the object id of what is being dragged, to limit the dragging behavior to a single object per drag. It works, however that seems like a poor solution: my Javascripting experience is it's a poor design to use global variables a lot, because of variable scoping and the penalty associated with it. Is Torquescript is similar in that respect?
I have studied MouseDraggableBehavior from the BehaviorPlayground project, however it's kind of confusing. It's illustrating several things actually- snapping to the mouse position, and to provide a sticky drag behavior. It does not use a global variable, but also calls setMouseLocked() and schedule()- why? I honestly don't understand what it's doing there.
Oops I guess that is three questions. Thanks in advance for your Torquescript wisdom.
Alex
About the author
#2
09/22/2008 (6:08 pm)
Thanks, that is what I ended up doing. But isn't there a way to mark an input event as handled, so it won't descend through the entire stack of views?
Torque Owner Deozaan