Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: mimmog on April 09, 2015, 04:08:49 AM

Title: Menu enter from left
Post by: mimmog on April 09, 2015, 04:08:49 AM
Is possible to create one menu that enter from left and stop it on specific point ? I'm using TweenPosition but I have a problem because if the screen resolution change also the stop position must change....
Title: Re: Menu enter from left
Post by: ArenMook on April 09, 2015, 03:50:34 PM
Assuming you start the TweenPosition or SpringPosition from code, you get to specify the final point to animate to. Just simply calculate this point using something relative like screen size.
Title: Re: Menu enter from left
Post by: mimmog on April 09, 2015, 06:03:21 PM
Hi! thank you for your answer. I have solved using TweenPosition but I have another problem....
The menu is on the left out of the screen and it is anchored to UIRoot. It enter from left using TweenPosition using this code attached to it

  1. void Awake () {
  2.         tw = gameObject.GetComponent<TweenPosition>();
  3.         uiTweener = tw.GetComponent<UITweener>();
  4.         originalPosition = transform.localPosition;
  5.         TweenPosition.Begin(gameObject,1f,originalPosition);
  6.         //Take the x position from another object on the screen
  7.         tw.to.x = liveObj.transform.localPosition.x;
  8. }  
  9.  
  10. private void playTw(){
  11.     if(transform.localPosition.x == tw.from.x){
  12.         uiTweener.PlayForward();
  13.         setStateBonus(true);
  14.     }else{
  15.         uiTweener.PlayReverse();
  16.         setStateBonus(false);
  17.    }
  18.    GetComponent<UISprite>().ResetAndUpdateAnchors();
  19. }

All work fine but if I want to reset the sprite to the original position and also reset TweenPosition as if I had never used it, how can I do ? I have tried to use this code

  1. TweenPosition.Begin(gameObject,1f,originalPosition);
  2. uiTweener.ResetToBeginning();
  3. GetComponent<UISprite>().ResetAndUpdateAnchors();
  4. NGUITools.SetActive(gameObject,false);
  5. tw.enabled = true;
  6. setStateBonus(false);

but not work fine on device :( when the menu go back it not coming out the screen to the initial position but instead it work fine on Unity Player....why ?

This is the problem
Title: Re: Menu enter from left
Post by: ArenMook on April 12, 2015, 04:17:01 PM
Tween.Begin erases the existing values, replacing the "from" value with the current one. If you want to play it in reverse, just GetComponent<TweenPosition>().PlayReverse().