Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
cerulean

Negotiating multiple 'owners' of common tween…

Recommended Posts

I have a game in which when an object — let's say its a kitten — goes on one side of a border line (there are two, opposite sides of the screen), a blinking alert line needs to flash.

 

I set the flashing alert to be a tweenmax, alpha on and off, repeat:-1, yoyo:true.

 

The issue I'm dealing with is there are maybe a hundred kittens. I need to have the tween running when any of them is the 'wrong side of the line' and off when all are on the right side of the line (again, there are two lines, but you get the idea). When they are all back in the kitty-corral then the tween needs not just to stop, or disappear (be killed), but tween alpha to 0.

 

I can think of several ways to handle this, but not an elegant way. I feel certain that there is something in the Overwrite manager that would help me — but I'm not sure. I don't think I can simply kill() the tween since there's no bringToCompletion flag as there is with killAll — and in any case how do I make it so one kitten doesn't ruin it for everyone (i.e. killing the tween before everyone is home).

 

I ended up just keeping a flag count and on ENTER_FRAME checking it, when it was 0 then tween the tween to 0. But it wasn't that elegant and wasn't working that well.

 

Does anyone perhaps have a better suggestion? Thanks for any help!

Link to post
Share on other sites

I think the appropriate way of handling this sort of thing is to separate the logic a bit. You shouldn't have every single kitten creating tweens for the flashing alert every time they cross the line. Instead, have a single class or function that manages the state of that flashing alert. Maybe you have a simple counter variable that keeps track of how many kittens are crossed over (a kitten calls a function that increments or decrements the value whenever it crosses over/out). When the value hits 0, you kill() the repeating tween and create a new one that animates alpha to 0. If the value goes from 0 to 1, you create a repeating TweenMax that does the flashing again. Every time it goes higher than one, you don't really have to do anything besides keeping track of the value so that when it gets decremented all the way to 0, you know you've got to fade it out again. 

 

Does that help? 

  • Like 1
Link to post
Share on other sites

I think the appropriate way of handling this sort of thing is to separate the logic a bit. You shouldn't have every single kitten creating tweens for the flashing alert every time they cross the line. Instead, have a single class or function that manages the state of that flashing alert. Maybe you have a simple counter variable that keeps track of how many kittens are crossed over (a kitten calls a function that increments or decrements the value whenever it crosses over/out). When the value hits 0, you kill() the repeating tween and create a new one that animates alpha to 0. If the value goes from 0 to 1, you create a repeating TweenMax that does the flashing again. Every time it goes higher than one, you don't really have to do anything besides keeping track of the value so that when it gets decremented all the way to 0, you know you've got to fade it out again. 

 

Does that help? 

Thanks -- that's what I ended up doing —

 

And now, in the end, they decided they wanted the kittens to flash!  (Which is easy) :-.

Link to post
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.

×