Author Topic: UIScrollView onStoppedMoving Issue  (Read 6849 times)

stevej

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 117
    • View Profile
UIScrollView onStoppedMoving Issue
« on: October 09, 2016, 04:13:59 AM »
I have a map that centers (UICenterOnChild) on a marker at the player's location. When the player drags the map around to look at other areas, and then releases, I want the map to snap back to the centered on player location. I'm finding though that it first returns to another point, and THEN the event fires and it moves to the centered on player spot. I can't figure out what's causing that in-between relocation and how to turn it off. It seems to be a default reset of some kind?

  1. ScrollViewMap = GameObject.Find("ScrollViewMap").GetComponent<UIScrollView>();
  2. CenterOnChildMap = ScrollViewMap.GetComponent<UICenterOnChild>();
  3. ScrollViewMap.onStoppedMoving += MapReturnToCenter;
  4.  

  1. public void MapReturnToCenter()
  2. {
  3.     CenterOnChildMap.CenterOn(SpriteMapMarker.transform);
  4. }
  5.  

https://youtu.be/7U7e3mTf1_4

stevej

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 117
    • View Profile
Re: UIScrollView onStoppedMoving Issue
« Reply #1 on: October 09, 2016, 08:29:06 PM »
To clarify, now that I've spent more time on this, I guess it's the "spring" behaviour that I want to disable. None of the settings on the UIScrollView seem to turn it off though? I figured Drag Effect "None" would do it, but no dice :(

And, just to add another question while I'm at it ... :) ... When the map displays, I'm firing my "Map Reset" code which basically just does the centering on the map marker. For some reason though, it doesn't work the first time you open the map. Only every time after that (see video). If anyone has any clues as to why that might be, I'd love some hints because it's kind of crappy as it is, and I'm stumped if I can figure out why it's not doing it the first time with the exact same "Map Show" code.

https://youtu.be/4e6QJRfaKEA

stevej

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 117
    • View Profile
Re: UIScrollView onStoppedMoving Issue
« Reply #2 on: October 10, 2016, 05:31:12 PM »
Just came across this thread:
http://www.tasharen.com/forum/index.php?topic=7332.msg34752#msg34752

And this comment:
Quote
UICenterOnChild needs to go on the object directly above children. In your case -- the "grid" object.

I'm also not sure why you have a "vertical sprite to scroll" object there and why everything else is a child of it. The hierarchy should be:

Scroll view
- Grid
-- child
-- child
-- child

In my hierarchy, things look like this:

Scroll View, CenterOnChild
- Map_0
-- tile
-- tile
-- map marker
- Map_1
-- tile
-- tile
-- map marker
- Map_2
-- tile
-- tile
-- map marker

And yet, when I call CenterOn for the "map marker" (only one Map_X is active at a time), it works.

Was the behaviour changed so that CenterOnChild can now navigate through a tree - i.e. not just direct children - or, could this hierarchy be contributing to my problem, even though that CenterOn part does seem to work?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView onStoppedMoving Issue
« Reply #3 on: October 11, 2016, 10:44:22 AM »
Center on child script is for scroll views. I am not sure why you're trying to use it for a world map... If you want to center on an object, do just that. Don't rely on the center script to pick an object for you -- as that's what it does. Like I said, scroll views. Certainly not meant for maps.

If you're dead-set on using a UI component, check the UICenterOnClick script for an example of code needed to move a panel to the target position.