Jump to content
Search Community

TweenLite update function for a game?

Secretmapper test
Moderator Tag

Recommended Posts

Hello. I have used TweenLite and It's been great! Very easy to use and loads of features. However, I have a quick question for any of you out there.

 

I'm making a game for class, and I have made the game loop have an update() function, and pausing the game means not calling that function. Now, you could probably already guess where this question is headed, but:

 

What would be the best way to handle this if I am aiming to use TweenLite? Pausing my game simply means not calling update, however, tweenlite relies on one call, not repetitive calls, so not calling update would obviously mean that tweenLite still runs.

 

Help Anyone? I know I could just call pause on them every time the game pauses, but If you know of any other more 'elegant' solutions, mind posting?

Link to comment
Share on other sites

Hi and welcome to the GreenSock forums. 

 

From my understanding of your question, it appears that TimelineLite's exportRoot() function is exactly what you need.

 

In short you can grab all your existing tweens, delayedCalls, and timelines and wrap them in TimelineLite that can be paused() and resumed(). The docs go into much more detail:

 

http://api.greensock.com/as/com/greensock/TimelineLite.html#exportRoot()

 

--- 

 

To get a glimpse of how this works you can 

 

1: visit http://www.greensock.com/gsap-js/

2: while the animation is playing click on the "getGSAP" button in the top left

3: notice that the animation is automatically paused

4: close the download screen

5: notice the animation resumes.

 

This is accomplished with exportRoot(). When the download gsap screen is activated it is not saying "stop the main animation", its calling exportRoot() which grabs any and all active tweens, wrapping them in a timeline and then pausing it.

 

This is a great way of doing a "global pause" without having to store references to every tween that is running.

 

Let us know if this is what you were looking for.

  • Like 1
Link to comment
Share on other sites

Interesting, I never saw this method before thanks!

 

However, how would I set the duration for an 'indefinite amount of time', and resume only after an event? 

 

Also, one problem I find here is that it will run the tween if ever I pause at a time where my code is still checking non-tween. I can't word it nicely, but here is some pseudocode:

 

update()

{

//lines and lines of code :)

 

TweenLite.to(view, 0.4, { scaleX:0.9, scaleY:0.9, ease:Linear.easeNone, onComplete:removeDead } );

}

 

Thing is, If I'm running '//lines and lines of code' while I export root, the next tweenLite command is going to run!

 

Sorry, I'm new in using GSAP. I probably should have read the docs and used TimeLine more :)

 

EDIT: I was searching in google and found this: http://forums.greensock.com/topic/6775-use-gsap-ticker-for-htmlcanvas-games-update/?hl=game+loop. There's a ticker function in Greensock? I can't find it in the docs.

Link to comment
Share on other sites

Here are the docs for the ticker: http://api.greensock.com/as/com/greensock/TweenLite.html#ticker


Note this was added in v12 (most recent version) of the platform. 

 

---

 

I don't think I know enough about your game setup or your latest explanation to give great advice.

 

If you remove your ENTER_FRAME listener for onUpdate before you exportRoot I don't think you are going to have rogue tweens created after the export. Probably worth investigating though.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...