Author Topic: Best Practices for Virtual Analog Stick(s)  (Read 6115 times)

blitzer

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 52
    • View Profile
Best Practices for Virtual Analog Stick(s)
« on: March 05, 2014, 03:07:40 PM »
Hello everyone,

I'm new to NGUI (and to UI in general), and I was hoping that someone could point me in the right direction when it comes to programming virtual analog sticks for touch devices.

With NGUI, the task of making a button draggable and having that button return seems easy enough (the components for that type of behavior are built in), but I was wondering how translating that movement into input for scripts was handled (say for moving a player around with that virtual analog stick). Off the top of my head, I suppose you could compare that current position of the analog stick to its starting position, and then take the difference and turn it into input a script could use (so if the stick is normally at say 0 0 0, if it was moved to 0 10(y) 0, the difference on Y would be positive and a script condition would be met and the player would start moving forward....or something like that).

So I was just wondering what the preferred method of getting input like this is when working with virtual analog sticks, any advice is appreciated.

BeShifty

  • Jr. Member
  • **
  • Thank You
  • -Given: 5
  • -Receive: 7
  • Posts: 52
    • View Profile
Re: Best Practices for Virtual Analog Stick(s)
« Reply #1 on: March 05, 2014, 06:59:55 PM »
I'd create a joystick class that manages the manipulation of the various sprites, and exposes a public Vector2 Direction property. The Player class in Update() reads that Direction and applies it as needed.

blitzer

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 52
    • View Profile
Re: Best Practices for Virtual Analog Stick(s)
« Reply #2 on: March 06, 2014, 01:32:16 PM »
Interesting, I'll give it a try, thank you for the advice.