Author Topic: reparent a sprite  (Read 3130 times)

ramiro

  • Guest
reparent a sprite
« on: January 02, 2014, 06:25:03 PM »
Hello all,

Very very new to NGUI and what not, and very low on the scripting totem pole :)

Here is my question. I have a sprite in a grid inside a scrollable panel. I can drag that piece out an onto the game panel with no problems. What I want to do is the following - If the user releases this piece anywhere outside of a specified "drop" area, I want the piece to return to where it was in the grid inside the scrollview. Make sense?

I am making a simple puzzle and just want to be sure the piece is where it belongs, if not go back into the grid.

Thanks in advance,
Ramiro

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: reparent a sprite
« Reply #1 on: January 03, 2014, 04:04:24 AM »
Have you watched the NGUI 3.0.7 tutorial at all? Because that's exactly how drag & drop behaves.

ramiro

  • Guest
Re: reparent a sprite
« Reply #2 on: January 03, 2014, 01:37:21 PM »
Hey Aren,

I have looked at it thanks. The real issue I am having is because I don't write code, and so I am using Playmaker to fire off events based on NGUI events. Here is what is happening.

I have the pieces inside the grid which is inside the scrollview. When the user drags on the scrollview it scrolls as expected(this works great!) except when the user happens to click on a piece rather than the scroll area and drags the piece. I have an FSM that tells the piece onPressRelease place the piece in its final position.

I need the logic to say if the user clicks on the piece and scrolls, don't fire off the place event, but rather just scroll, and if the user drags the piece out of the scroll view then and only then fire off the place event(not sure how to figure out what that area is and how to tell NGUI/Playmaker about it without code).

Once dragged out of the scrollview, if piece is near it's drop area and released(best way to define what this is?) then fire off a place event. I just don't know how to set that up, and I have been so frustrated the last few days... aaarrgggg!!!

I tried using a trigger based setup but also came up short. By the way I absolutely love NGUI so far :)

Hope this clarifies a bit. Any help you can offer would be huge, I can feel I am so close to getting this to work, but I am banging my head in vain!!

Thanks a million Aren....

Ramiro

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: reparent a sprite
« Reply #3 on: January 04, 2014, 08:44:15 AM »
Unfortunately there is little I can do in regards to Playmaker. I didn't write any code in the video tutorial, and the functionality behaved as you desired. Scrolling when dragging horizontally, drag & drop when dragging vertically.

Don't forget to add proper scripts to the scroll view's items as well. Everything inside the scroll view that has a collider must have the Drag Scrollview script attached or you won't be able to drag it.