Author Topic: About UIdrag object  (Read 4027 times)

locky4ever

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
About UIdrag object
« on: September 22, 2014, 04:07:19 AM »
Hello,I'm new here and I just use NGUI for less than 1 month.
I just want to make a Demo that I can move things which have collision each others in the restricted screen.Now I have do almost of them by UIdrag object. But there's still a question that if I drag one object to another object ,it can be outside of the screen and get lost by the user.
How to make them stay in the screen?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: About UIdrag object
« Reply #1 on: September 22, 2014, 10:19:39 AM »
UIDragObject script has the "Keep Visible" option that lets you do that, assuming you're using widgets and not 3D objects.

locky4ever

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: About UIdrag object
« Reply #2 on: September 22, 2014, 08:10:02 PM »
hmmm...I use the Sprite with physics 2D and the Camera which is in the UI root with 2D UI.
And it works well when I drag one Sprite in the screen.
If I push Sprite A with Sprite B slowly,Sprite A will go out of the screen and get out of the control.
Now I make four object with edge Collider 2D around the screen.
Sprite A won't get out of the screen if I pust it with B slowly.
But another question is B will shoot out of the screen with the springstrength if the mouse go out of the screen to much when I push A with B.
I think the keyword is slowly.
What should I do? :'(

recon03

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: About UIdrag object
« Reply #3 on: September 22, 2014, 09:42:41 PM »
I  just made a post about this as well, it works great but it springs off screen and back.  Not sure if NGUI can have it not leave the screen totally or not.   I would think it so, but all of the examples show this effect were it goes off the screen and springs back...

I hope there is a way to make  it were you can have  it never leave the screen ever... Hopefully Aren can commented on this soon since both of us are dealing with this .

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: About UIdrag object
« Reply #4 on: September 23, 2014, 11:20:10 AM »
The "keep visible" option isn't meant to track changes every frame, only while you're dragging the sprite. It's done this way for performance, as it's a UI element, not a game element. If you want to have logic that keeps the sprite on screen at all times and account for it being moved by other sprites (physics etc), then you need to have a script that does a persistent visibility/on screen checking, not periodic like NGUI's. This would be game logic code.