Author Topic: Switch focus from Button to DragObject  (Read 1634 times)

mushu

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Switch focus from Button to DragObject
« 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.



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)
« Last Edit: October 21, 2013, 07:51:30 AM by mushu »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Switch focus from Button to DragObject
« Reply #1 on: October 21, 2013, 01:26:23 PM »
UICamera.currentTouch.pressed needs to be set to your new object.

mushu

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Switch focus from Button to DragObject
« Reply #2 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.