2D Toolkit Forum

2D Toolkit => Support => Topic started by: rrl on July 18, 2013, 02:19:19 am

Title: Draggable tk2dUIItem created on mouse down to be draggable with same mouse down
Post by: rrl on July 18, 2013, 02:19:19 am
So, I have a list of tk2dTextMesh game objects that, when any one of them are clicked, are supposed to spawn a tk2dSprite game object that is normally draggable. The problem is that when I click the TextMesh object to create the Sprite object and continue holding the mouse button down, the Sprite object isn't draggable (though it is draggable if I release and click again). This seems to make sense to me since, I'm assuming, it's because the raycast that tells the UI manager which object was hit on mouse down it reporting the TextMesh and not the Sprite... though I could be wrong.

My question is... is this possible in any way with 2d Toolkit presently? It wouldn't be the end of the world if I had to make a separate raycast somewhere else in the code for this one situation, but... just though I should check here first.
Title: Re: Draggable tk2dUIItem created on mouse down to be draggable with same mouse down
Post by: unikronsoftware on July 18, 2013, 10:01:21 am
Once you create it, get the tk2dUIDragItem, and try calling ButtonDown() on it. It should start dragging it. Not tried it, but it looks like it should from the source.
Title: Re: Draggable tk2dUIItem created on mouse down to be draggable with same mouse down
Post by: rrl on July 18, 2013, 07:32:26 pm
Thanks for the response, but unfortunately it doesn't seem to work. I printed some values to the debug log and when I call Button Down manually, the "pos" value in the CalculateNewPos function remains 0,0 until I release and click again. Not sure if that's a clue as to what's going on, but that's the only thing that seemed weird to me. The line in question below:

Vector2 pos = uiItem.Touch.position;
Title: Re: Draggable tk2dUIItem created on mouse down to be draggable with same mouse down
Post by: unikronsoftware on July 18, 2013, 08:33:05 pm
Yeah it is that. Since the button wasn't Touched to start with. If you can find a tk2dUITouch (i.e. from the triggering object), you can call Press on the new objects tk2dUIItem to trigger it.
Title: Re: Draggable tk2dUIItem created on mouse down to be draggable with same mouse down
Post by: rrl on July 18, 2013, 08:41:51 pm
Okay, that makes enough sense. I'll see what I can do. Thanks for all the help.