Author Topic: Menu enter from left  (Read 3436 times)

mimmog

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Menu enter from left
« 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....

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Menu enter from left
« Reply #1 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.

mimmog

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: Menu enter from left
« Reply #2 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
« Last Edit: April 10, 2015, 02:11:08 PM by mimmog »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Menu enter from left
« Reply #3 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().