Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: mushu on October 21, 2013, 07:12:55 AM

Title: Switch focus from Button to DragObject
Post by: mushu on October 21, 2013, 07:12:55 AM
Hi

I have a scenario where an joystick (drag object) has an arrow to the side. If the user presses the arrow the joystick should snap to under their finger and become the active UI component so when the user slides their finger, the joystick moves with it.

(http://imgur.com/IrTH6C1)

So, when the button is pressed I've gotten the code:

button.SendMessage("OnPress", false);      // Deactivate button
joystick.SendMessage("OnPress", true);     // Activate joystick

UICamera.currentTouch.dragged   = joystick;   // Make the joystick the camera's current drag object


Which works in that it results in the joystick being dragged after a finger is slid off the button BUT it seems that that breaks something else as the joystick doesn't move as it normally does (like when its pressed directly and ragged around. With my method via the button it jumps off the panel).

Is there already a way of doing this? Or if not how should I go about implementing the functionality?

P.S Here's the image link just incase: http://imgur.com/IrTH6C1 (wasn't displaying properly in the post for me)
Title: Re: Switch focus from Button to DragObject
Post by: ArenMook on October 21, 2013, 01:26:23 PM
UICamera.currentTouch.pressed needs to be set to your new object.
Title: Re: Switch focus from Button to DragObject
Post by: mushu on October 22, 2013, 01:24:06 AM
Great thanks ArenMook!!!

And for anyone that may be interested, this is the working code block:

UICamera.currentTouch.pressed = dragObject;
button.SendMessage("OnPress", false);
dragObject.SendMessage("OnPress", true);
UICamera.currentTouch.dragged = dragObject;


P.S This works for me but if the order of commands is wrong please let me know.