Set mouse cursor position
by anycast · in Torque Game Builder · 01/07/2009 (9:16 am) · 5 replies
Hi all,
I'm trying to restrict mouse movement while dragging. I can capture the mouse position with the onMouseDragged callback, but I'm not finding any way to set the mouse cursor position (to make it stick within bounds). How do I accomplish this?
Thanks in advance!
Alex
I'm trying to restrict mouse movement while dragging. I can capture the mouse position with the onMouseDragged callback, but I'm not finding any way to set the mouse cursor position (to make it stick within bounds). How do I accomplish this?
Thanks in advance!
Alex
About the author
#2
10/23/2009 (5:05 am)
I am having the same issue, mouse doesn't adhere to the world limits of the sprite you have clicked and are dragging?
#3
10/27/2009 (8:39 pm)
It's not possible within TGB. You would need to restict the mouse using the OS... which I don't think is even possible. It would be hard to justify why the OS would restrict the mouse pointer to a particular portion of the screen.
#4
Not exactly true.
While I don't know of any way to lock the mouse within a given area, it is possible to reset the position of the mouse within TGB using sceneWindow2D.setMousePosition(%positionHere) so if you're willing to spend some time you could check to see if the current position is valid and if it isn't, move the mouse back to a valid position. I've read the question in the post above yours a few times but I'm still not exactly sure what he is trying to do so I can't offer any more specific help.
10/28/2009 (4:37 pm)
Quote: It's not possible within TGB. You would need to restict the mouse using the OS... which I don't think is even possible. It would be hard to justify why the OS would restrict the mouse pointer to a particular portion of the screen.
Not exactly true.
While I don't know of any way to lock the mouse within a given area, it is possible to reset the position of the mouse within TGB using sceneWindow2D.setMousePosition(%positionHere) so if you're willing to spend some time you could check to see if the current position is valid and if it isn't, move the mouse back to a valid position. I've read the question in the post above yours a few times but I'm still not exactly sure what he is trying to do so I can't offer any more specific help.
#5
Hope it helps!
10/28/2009 (6:22 pm)
I'm not sure if this will work as is - or if you'll be able to adapt it - but I had it laying around so I thought I'd share. Perhaps you could set your draggable object's superclass as mouseCatcher and toggle it in the onMouseDown callback or something.function mouseCatcher::onLevelLoaded(%this, %scenegraph)
{
%this.enableUpdateCallback();
%this.xMin = %this.getPositionX() - (%this.getWidth() / 2);
%this.xMax = %this.getPositionX() + (%this.getWidth() / 2);
%this.yMin = %this.getPositionY() - (%this.getHeight() / 2);
%this.yMax = %this.getPositionY() + (%this.getHeight() / 2);
}
function mouseCatcher::onUpdate(%this)
{
if(getWord(sceneWindow2d.getMousePosition(),0) < %this.xMin)
{
sceneWindow2d.setMousePosition(%this.xMin,getWord(sceneWindow2d.getMousePosition(),1));
}
else if(getWord(sceneWindow2d.getMousePosition(),0) > %this.xMax)
{
sceneWindow2d.setMousePosition(%this.xMax,getWord(sceneWindow2d.getMousePosition(),1));
}
else if(getWord(sceneWindow2d.getMousePosition(),1) < %this.yMin)
{
sceneWindow2d.setMousePosition(getWord(sceneWindow2d.getMousePosition(),0),%this.yMin);
}
else if(getWord(sceneWindow2d.getMousePosition(),1) > %this.yMax)
{
sceneWindow2d.setMousePosition(getWord(sceneWindow2d.getMousePosition(),0),%this.yMax);
}
}Hope it helps!
Torque Owner Ecliptic
Thanks as well!
Dane