Author Topic: [Solved] Pause tweens without modifying Time.timeScale  (Read 4417 times)

OnlineCop

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 51
    • View Profile
[Solved] Pause tweens without modifying Time.timeScale
« on: June 20, 2013, 05:09:03 PM »
I am using scale and position tweens for a twitch game. The GameObjects currently move, rotate, and scale around the screen correctly.

I am going to need a pause feature in the game, but pausing the game should not affect background animations, music, and some other UI element tweens.

I searched for other ways to "pause" a game and found many results here that discuss how to do this with Time.timeScale, but I don't believe that would work best for all the background things that I need to keep going.

Since I'll know my tween's initial duration as well as the starting and ending positions/scales, could I just grab its current tween time, then unsubscribe the tween? Then when the player resumes, I could manually interpolate the values (or restore them from saved values) and resubscribe the tween to "finish" their operations.

Or is there a better way already in place?  ;)
« Last Edit: June 26, 2013, 11:03:48 AM by OnlineCop »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Pause tweens without modifying Time.timeScale
« Reply #1 on: June 21, 2013, 05:37:49 AM »
Time.timeScale = 0.

NGUI's content is timescale-independent. All tweens have an option on them to ignore the time scale. Any animations you trigger via ActiveAnimation.Play will also ignore time scale.

OnlineCop

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 51
    • View Profile
Re: Pause tweens without modifying Time.timeScale
« Reply #2 on: June 21, 2013, 11:25:55 AM »
Right; I don't want to Time.timeScale = 0 because it'll affect all my background stuff.

What I want to do is pause the tweens themselves, while continuing all the rest of the game logic (background animations, music, particle effects, etc.).

Essentially, the only things that I do want to pause are NGUI's UITweener events (such as TweenPosition, TweenScale, etc.), not the other way around.

What about grabbing UITweener.tweenFactor, so I know how far it's gone so far in its tween, call UITweener.Sample() to update its localPosition, and then grab that localPosition value? That should give me the interpolated values and time spent on the tween, and then I could disable the tweener (you CAN disable them, right?) while the app is "paused". I would then just create a new tween from its current position and put in the remaining time so it continues on its path at the same speed as before the pause event happened.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Pause tweens without modifying Time.timeScale
« Reply #3 on: June 22, 2013, 06:02:51 AM »
You can't do what you are trying to do via timeScale. You can't pause the UI while letting the game run. Only the other way around.

If you want to pause tweens, then just disable the tween components.

OnlineCop

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 51
    • View Profile
Re: Pause tweens without modifying Time.timeScale
« Reply #4 on: June 24, 2013, 07:59:42 PM »
Disabling the components did it. I didn't even think to try that.

Thanks for answering the question for me!