Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: madmat3001 on December 10, 2012, 10:31:18 AM

Title: Moving a scroll view from code, one item at a time
Post by: madmat3001 on December 10, 2012, 10:31:18 AM
I followed this example (http://"http://www.tasharen.com/?page_id=4444") to create a scroll view that centers on items.

So far everything works fine, but now I want to add buttons that can move the scroll view one item left / right at a time.

I'm using DraggablePanel.MoveRelative() to move the panel and I am splitting the move over a few frames to make it look smooth.

Now sometimes this works perfectly, but sometimes the position of the DraggablePanel is changed between two calls of MoveRelative() and as a result the panel wont move far enough for the centering to center on the next item.

I have already tried to disable the UICenterOnItem Script during the move and re-enabling it after, which did not help.

What other components might be changing the DraggablePanel's position?
Title: Re: Moving a scroll view from code, one item at a time
Post by: ArenMook on December 10, 2012, 12:30:33 PM
Easiest way to find out is to put some Debug.Log statements in that script. Off the top of my head I can't tell you much.
Title: Re: Moving a scroll view from code, one item at a time
Post by: madmat3001 on December 11, 2012, 08:25:30 AM
Yeah, I've tried that. I can say for sure, that no other component is calling MoveRelative() (or MoveAbsolute() for that matter).

But I have just found a component "SpringPanel" that's attached to my DraggablePanel during runtime, but not during design time (Which is why I haven't noticed it 'til now). I have not yet dug deeply into the code, but at first glance it seems like a possible culprit.

What does it do and where does it come from?
Title: Re: Moving a scroll view from code, one item at a time
Post by: ArenMook on December 11, 2012, 03:31:20 PM
SpringPanel is what's used to move the panel when you let go of the mouse button/touch. It adds a "spring" effect to it rather than stopping movement outright.
Title: Re: Moving a scroll view from code, one item at a time
Post by: madmat3001 on December 12, 2012, 06:01:07 AM
Fixed it.

It was indeed the SpringPanel which caused all my troubles. Now while the SpringPanel is usually only enabled for a short time, it sometimes stayed enabled after I moved the DraggablePanel using MoveRelative().

Now the next time I hit my button to move the DraggablePanel, the SpringPanel would still be enabled and "counter act" my movement to a certain degree, resulting in the weird behaviour.

So for anybody else trying to implement "up/down" or "left/right" buttons for their scroll views, make sure to disable the SpringPanel before you call DraggablePanel.MoveRelative()

I wonder how nobody had this problem before, as I'm sure having scroll button like this is a rather common feature, isn't it?
Title: Re: Moving a scroll view from code, one item at a time
Post by: ArenMook on December 12, 2012, 12:36:48 PM
I guess not! :)