Author Topic: Tweener Position Behavior "left to Center" - "Center to right"  (Read 3526 times)

trenrod

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 4
    • View Profile
Hi,  (I use 3.6.6)

i have a menu where a new menu fades in from right to center. When another menu is selected the current menu fades out from center to left while the new menu fades in from right to center.

I have tried different approaches for hours. The most promising was after the menu is triggered to fade out, I first manupulate the "to" values and simply play reverse. Like "transform.GetComponent<TweenPosition>().from = new Vector3(0, -48, 0);"
=> This results in very strange things like dissapearing parts of the menu. Clicking somewhere does make them appear again. When i remove the changes in TweenerPosition.to they does not dissapear.

Btw. I do use NGUITools.SetActive(gObj, true/false) after a menu is triggered to appear and to dissapear.

A hint would be very kind. If it helps I will try to seperate this behavior into an example file.

Thank you very much.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tweener Position Behavior "left to Center" - "Center to right"
« Reply #1 on: June 29, 2014, 10:41:48 PM »
To tween to a specific location, use TweenPosition.Begin. It will add a tween if it's missing, and will use the current position as the "from" value. UIPlayTween script can activate a tween for you, playing it in a specific direction, and it can also enable the game object if it's disabled.

Have you looked at the example menu that comes with NGUI? It uses tweens.

trenrod

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 4
    • View Profile
Re: Tweener Position Behavior "left to Center" - "Center to right"
« Reply #2 on: June 30, 2014, 02:21:35 PM »
Hi,

thank you for the fast reply.

Yes, I have looked at your example but but it uses animations which would be to much overhead for my project.

Using TweenPosition.Begin results in the same strange behavior. (The animation itself works as expected, but parts of the menu disapears)

Below the important parts.
  1.         public void doFadeOut(){
  2.                 TweenPosition.Begin(this.gameObject, 1f, new Vector3(-432, -48, 0));
  3.                 currentState = State.FADE_OUT;
  4.         }
  5.  
  6.         public void doFadeIn(){
  7.                 transform.position = transform.parent.TransformPoint(new Vector3(432, -48, 0));
  8.                 NGUITools.SetActive(gameObject, true);
  9.                 TweenPosition.Begin(this.gameObject, 1f, new Vector3(0, -48, 0));
  10.                 currentState = State.FADE_IN;
  11.         }
  12.  
  13.         // Started after the animation ends
  14.         public void performStateAfterFade(){
  15.                 if(currentState == State.FADE_IN){
  16.                         currentState = State.VISIBLE;
  17.                 }else{
  18.                         currentState = State.HIDDEN;
  19.                         NGUITools.SetActive(gameObject, false);
  20.                 }
  21.         }
  22.  
  23.  

Attached few images to makes it more clear.

Initial state first menu(1) is Active, 2nd menu(2) is Inactive.

[init.png] Initial screen after start.
[item_clicked.png] If an item was selected the method "doFadeOut" is started on the current menu(1) and "doFadeIn" on the next menu(2).
[back_toOverview.png] Pressing "Overview" Button triggers "doFadeOut" for the current one menu(2) and "doFadeIn" for the menu(1).
[item_clicked_again.png] Selcting another item from menu(1) does the same like in [item_clicked.png]. Starts method fadeOut on menu(1) and fadeIn on menu(2)

I had the same behavior in menu(1) also.

If I do not change the "from" or "to" of the current Tween items does not dissapear.

Thank you very much.



ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tweener Position Behavior "left to Center" - "Center to right"
« Reply #3 on: July 01, 2014, 04:30:52 AM »
  1. transform.position = transform.parent.TransformPoint(new Vector3(432, -48, 0));
You should be changing localPosition, not position. And why do you transform the point? Why not just..
  1. transform.localPosition = new Vector3(432, -48, 0);
?

You also seem to be calling the function of a disabled object... you should instead call functions on only enabled objects. Instead of using 'gameObject', have a 'target' value like I do with UIPlayTween.

If you can't figure out what's going on, you can send me a repro case to look at (support at tasharen.com). It's easier than screenshots.

trenrod

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 4
    • View Profile
Re: Tweener Position Behavior "left to Center" - "Center to right"
« Reply #4 on: July 28, 2014, 07:44:29 PM »
Problem: The problem was that I did not let any update happen between adding the items to the grid, and starting the Tweener.
Solution: Now that I trigger the Tweener during an Update. Everthing works as expected.