Drag and Drop
by Kevin James · in Torque Game Builder · 04/08/2005 (8:13 pm) · 30 replies
I have characters on one side in the scenegraph and a window on the other side containing sprites. I want to drag and drop these sprites onto the characters using the mouse. Will this work from a gui screen (drag) to the scenegraph(drop)?
Does anyone have example script of drag and drop?
Does anyone have example script of drag and drop?
About the author
Computer security, digital forensics, and platform jumper enthusiast. shells.myw3b.net/~syreal/
#2
04/08/2005 (9:06 pm)
Thanks King Bob!
#3
04/08/2005 (9:29 pm)
Sure :) btw the first tutorial will probably be all you need... the second one goes over a more advanced method... the third one goes over debuging info... I very much recommend them, but the simple selection 'should' work fine for what your doing
#4
in onMouseDown I have this (along with everything else above it):
and the echo shows true.
but... in onMouseDragged it echos false:
However, if I echo this in OnMouseDragged:
It echos "Test Box" as expected.
As a result of all of this, my tile does not move:
because %this.objectSelected is not keeping its value. I'm gonna try and rewrite this to work, but I wanted you to be aware of my experience. I assume this only acts this way for me.
04/09/2005 (1:19 pm)
I'm following the tutorial and this is what is happening to me:in onMouseDown I have this (along with everything else above it):
if(%selected)
{ //we then store that object as the selectedObj
%this.selectedObj = %obj;
%this.objectSelected = true;
echo("objectselected=" SPC %this.objectSelected);
}and the echo shows true.
but... in onMouseDragged it echos false:
//lets store the mouses position
%this.mousePos = %worldPos;
%this.objectFollowCheck();
echo("objectselected=" SPC %this.objectseleted);However, if I echo this in OnMouseDragged:
echo("You have dragged:" SPC %this.selectedObj.objectname);It echos "Test Box" as expected.
As a result of all of this, my tile does not move:
function fxSceneWindow2D::objectFollowCheck()
{
if(%this.objectSelected){
%obj = %this.selectedObj;
%mousePos = %this.mousePos;
%obj.setPosition(%mousePos);
}
}because %this.objectSelected is not keeping its value. I'm gonna try and rewrite this to work, but I wanted you to be aware of my experience. I assume this only acts this way for me.
#6
04/09/2005 (1:49 pm)
Now it wont let me selet anything else. is there something special that needs done for animated sprites or mounted sprites?
#7
so say you have $object
$object.isSelectable = true;
$player.isSelectable = true;
or you can comment out my loop that checks if an object is selectable, though it will only pick one out of a stack of objects if they're layered :O)
04/09/2005 (2:23 pm)
Remember set a property to the object you want selected... ".isSelectable = true;"so say you have $object
$object.isSelectable = true;
$player.isSelectable = true;
or you can comment out my loop that checks if an object is selectable, though it will only pick one out of a stack of objects if they're layered :O)
#8
For some reason, in here:
%obj returns me the same number, no matter what guy I click. I have several rows and columns of characters in multiple layers, but its not finding the right one for some reason.
04/09/2005 (2:39 pm)
Yes, I did that.For some reason, in here:
for(%i=0;%i<%objCount;%i++) {
//grabing the entry corresponding to the loop
%obj = getWord(%objList, %i);
echo("You have selected:" SPC %obj);%obj returns me the same number, no matter what guy I click. I have several rows and columns of characters in multiple layers, but its not finding the right one for some reason.
#9
04/09/2005 (3:05 pm)
I stuck in %selected = true; right after the loop and the object that gets moved is the background.... which is 1 in the list, 0 is not an object. This problem goes way beyond having my IsSelecable turned on- its not seeing my sprites at all.
#10
that way it picks the last item in the list...
04/09/2005 (3:25 pm)
Right now its returning the first object in the list, which is the background... to make it select the topmost object do this%objCount = getWordCount(%objList) - 1;
%obj = getWord(%objList, %objCount);
echo("You have selected:" SPC %obj);that way it picks the last item in the list...
#11
objList = t2dSceneGraph.pickPoint(%worldPos);
can be changed to use group and layer masks
objList = t2dSceneGraph.pickPoint(%worldPos, BIT(1), BIT(1));
so you can fine tune it even more
04/09/2005 (3:29 pm)
By specifying isSelectable tells it to pick the first one with that option toggled to true...objList = t2dSceneGraph.pickPoint(%worldPos);
can be changed to use group and layer masks
objList = t2dSceneGraph.pickPoint(%worldPos, BIT(1), BIT(1));
so you can fine tune it even more
#12
$Character[%n].setCollisionPolyCustom(4,"-0.5 1 0.5 1 0.5 -0.7 -0.5 -0.7");
when i take that out, I can pick him up with the mouse. Ummm... I really do need to have a custom poly. I'm just grasping at straws here, but does the order of setting these properties matter?
04/09/2005 (3:30 pm)
Thru tedious trial and error I narrowed it down to this:$Character[%n].setCollisionPolyCustom(4,"-0.5 1 0.5 1 0.5 -0.7 -0.5 -0.7");
when i take that out, I can pick him up with the mouse. Ummm... I really do need to have a custom poly. I'm just grasping at straws here, but does the order of setting these properties matter?
setPosition( "0 0" ); setGroup(1 ); setLayer(1); setCollisionActive(true,true ); setCollisionPolyCustom(4,"-0.5 1 0.5 1 0.5 -0.7 -0.5 -0.7"); setCollisionMasks(BIT(2),BIT(2)); setCollisionCallback(true ); playAnimation($Character[%n].Taunt);
#13
your set up seems fine
04/09/2005 (3:31 pm)
One thing to keep in mind, I think the pick function works off of collision polys or bounding boxes, so if you set a custom poly you will probably have to click within that collision poly (I'm not completely sure thoughyour set up seems fine
#14
i tried that, but it still doesn't work (when using poly)
04/09/2005 (3:39 pm)
Quote:With custom poly turned on, there's only 1 object in the list, the background.
Right now its returning the first object in the list, which is the background... to make it select the topmost object do this
Quote:
objList = t2dSceneGraph.pickPoint(%worldPos, BIT(1), BIT(1));
i tried that, but it still doesn't work (when using poly)
#15
04/09/2005 (3:42 pm)
If collision is active you must select the object within the collision poly
#16
04/09/2005 (3:42 pm)
My poly narrows the square around the sprite for better precision. Its not hard to click within it. I'll try adjusting the size and see what happens.
#17
$test.setCollisionPolyCustom( 5, "-0.9 0 0 -0.6 1 -0.3 1 0.3 0 0.5" );
it works selecting within the collision poly
when i set it to yours it doesnt
$test.setCollisionPolyCustom(4,"-0.5 1 0.5 1 0.5 -0.7 -0.5 -0.7");
04/09/2005 (3:43 pm)
Ok now I'm really confused... when i set the collision poly to this$test.setCollisionPolyCustom( 5, "-0.9 0 0 -0.6 1 -0.3 1 0.3 0 0.5" );
it works selecting within the collision poly
when i set it to yours it doesnt
$test.setCollisionPolyCustom(4,"-0.5 1 0.5 1 0.5 -0.7 -0.5 -0.7");
#18
04/09/2005 (3:48 pm)
Very interesting...
#19
04/09/2005 (3:49 pm)
Hmm, yeah, even realtime... wonder if its some sort of bug
#20
click and moving
moving works
set collision to the new poly, its accepted and set
click and moving doesnt work
04/09/2005 (3:58 pm)
Setting collsion poly to one from tutorial (for enemies)
Torque 3D Owner Matthew Langley
Torque
T2D Tutorial Mouse Object Selection and Moving Part 2
T2D Tutorial Mouse Object Selection and Moving Part 3