Author Topic: Dragging  (Read 6296 times)

kodagames

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Dragging
« on: April 17, 2012, 10:32:49 PM »
Hello All,

I've just purchased NGui after playing with the demo and its quite nice.

Does anyone know how I would go about dragging a button from one box and have it snap to the center of another box? When I mention box it could be a sliced sprite, image background etc...

I can get a simple button to drag with UIDragObject and I've tried messing around with UIDragPanelContents, UIGrid, UITable, DragDropItem etc.. but just can't seem to get anything to do what I want.

Can someone try and help me figure this out? From the image Im trying to drag a button from the box and have it snap to one of the other boxes and be centered. Right now when I drag the button it just lands anywhere I let go of the mouse instead of on one of the boxes and I haven't a clue as to how to do this.

Sincerely,
Michael

 
« Last Edit: April 17, 2012, 10:35:49 PM by kodagames »

dlewis

  • Guest
Re: Dragging
« Reply #1 on: April 18, 2012, 12:08:42 AM »
The way I would attempt it would be to read the 'mouse up' event on the collider of the boxes, see if you are dragging anything (Possibly through all custom code) and then take that object and snap it to a point somehow.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dragging
« Reply #2 on: April 18, 2012, 12:37:38 AM »
Yeah that's pretty much it. Listen to the OnDrop() event, and when it arrives, reparent the object. Assuming the object's origin is at the center, you don't have to do anything else. I suggest starting with the drag & drop example.

kodagames

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: Dragging
« Reply #3 on: April 18, 2012, 08:58:10 PM »
Thanks Guys,

I need a little more help if you dont mind?

I have the UIDragObject script on my button to move it around (which is nice).

I created another script for testing (Javascript):

While dragging this button it will print dragging
  1. function OnDrag()
  2. {
  3.         Debug.Log("Dragging");
  4. }

How would I print a message or write the code to ask if dragging is false print stopped dragging?

  1. function OnDrag()
  2. {
  3.         //I know this is wrong but need help with the sysntax
  4.  
  5.         if(OnDrag() == false)
  6.         {
  7.                 Debug.Log("Stopped Dragging"); 
  8.         }
  9. }
  10.  

I need a little syntax help with this one.

ozRocker

  • Guest
Re: Dragging
« Reply #4 on: April 30, 2012, 07:09:05 AM »
I have the same question as the post above.  I'm trying to use OnDrag to determine the distance between Press and Release but I've noticed that the OnDrag event fires during the dragging, not when the dragging has completed.  Should I just be using OnPress(true) and OnPress(false) and comparing change in position instead?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dragging
« Reply #5 on: April 30, 2012, 07:12:31 AM »
UICamera.currentTouch.totalDelta