Hello Guest

Author Topic: Draggable tk2dUIItem created on mouse down to be draggable with same mouse down  (Read 4030 times)

rrl

  • Newbie
  • *
  • Posts: 3
    • View Profile
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.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
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.

rrl

  • Newbie
  • *
  • Posts: 3
    • View Profile
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;

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
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.

rrl

  • Newbie
  • *
  • Posts: 3
    • View Profile
Okay, that makes enough sense. I'll see what I can do. Thanks for all the help.