Jump to content
Search Community

Problem with mulitiple tween after each other

matthy test
Moderator Tag

Recommended Posts

Hi,

 

i have made a function that when you press a certain key on your keyboard the mc gives a glow (tweenMax)

the glow is in yoyo so after 2 seconds its gone again. the problem with this is when pressing to fast the tweens will stay and wont go away with the yoyo effect.

 

example

		public function Engine()
	{
		TweenMax.to(this.blok, 1, { glowFilter: { color:0xffff00, alpha:1, blurX:20, blurY:20, strength:3, quality:3 }, overwrite:2, repeat:1, yoyo:true } );

		var ExlodeTimer = new Timer(1400);
			ExlodeTimer.addEventListener(TimerEvent.TIMER, glow2);
			ExlodeTimer.start();
	}

	function glow2(e:Event)
	{
		TweenMax.to(this.blok, 1, { glowFilter: { color:0xcc0033, alpha:1, blurX:20, blurY:20, strength:3, quality:3 }, overwrite:2, repeat:1, yoyo:true } );
	}

 

example on: http://www.websitekeuken.nl/demo/test.swf

dl source file on: http://www.websitekeuken.nl/demo/test.zip

 

does anyone have a solution for this, so that it will go away?

 

thanks

matthy

Link to comment
Share on other sites

hi matthy,

 

i'm having a tough time understanding how the code you posted corresponds to the behavior you are trying to accomplish.

 

regardless, to prevent user interaction from messing with a tween that is running, you can test to see if a tween is already running like so:

 

mc.addEventListener(MouseEvent.CLICK, glow);

function glow(e:Event) {
if (! TweenMax.isTweening(mc)) {
	TweenMax.to(mc, 3, { glowFilter: { color:0xcc0033, alpha:1, blurX:20, blurY:20, strength:3, quality:3 },repeat:1, yoyo:true } );
} else {
	trace("stop clicking, i'm currently tweening!");
}
}

 

once the glow tween is initiated, it will appear then disappear even if the user clicks 20 times while the tween is running.

Link to comment
Share on other sites

hi matthy, i'm having a tough time understanding how the code you posted corresponds to the behavior you are trying to accomplish.

 

I am sorry if I was a bit unclear about everything.

What the best solution would be, if that the tween that is tweening goes away.

And the tween that has to be tweened replaces it.

 

So

1. Press -> gives yellow glow.

2. glow isnt finished

3 New Press gives -> red glow.

4. yellow glow removes itself and red glow appears.

 

Something even better would be that they could interact separate from each other, so you would have 2 glows trough each other and the glow would not react at each other in stead of whats happening right now.

 

i hope its clear rigth now else yust ask ;)

 

cheers

matthy

Link to comment
Share on other sites

ok, that makes it more clear. keep in mind the following

 

1: i'm guessing you are using KEY_DOWN. KEY_DOWN fires repeatedly while a key is held down.

 

test this code and hold down any key for 3 seconds.

 

stage.addEventListener(KeyboardEvent.KEY_DOWN, downHandler);


function downHandler(keyEvent:KeyboardEvent) {
trace("some key is down");
}

 

you will see that it traces as long as the key is held down. i imagine you are using this behavior to move your ship.

 

 

2: TweenMax.to() tweens always start at the display objects CURRENT value and tweens to the target value. yoyo brings them back to the starting value

 

---------------

 

what's happening with your glow tweens is that as you hold down a key (just a guess) the tweens are being constantly re-created with new starting values.

 

 

lets keep it simple and say every time you press a key an mc tweens to an x value of 100 with a duration of 2 seconds

this mc is on the stage with an x of 0.

TweenMax.to(mc, 2, {x:100, repeat:1, yoyo:true});

 

USER INTERACTION 1:Optimal

the instant you press a key the tween starts moving from 0 to 100. if you release quickly it will go to 100 and yoyo back to 0.

 

USER INTERACTION 2:reality

NOW, lets say you press a key to initiate the same tween.

mc starts at 0 making its way to x:100

 

1 second later you are STILL holding the key down. the tween gets regenerated and now you are starting a new tween at 50. you release. the mc moves from 50 to 100 and BACK to 50.

 

-------

 

i believe this is what is happening with your glows. (i don't know for sure as i haven't seen the code) if you start your swf and press a key very quickly the glow yoyos nicely.

as you repeatedly press more keys you are repeatedly starting new tweens with new start values.

 

 

 

--------

 

 

I can't trouble shoot your implementation without seeing it. at this point i would see if KEY_UP is acceptable (fires only once).

every time you tween to a new glow color, you might want to try using an onComplete handler to remove the glow as opposed to yoyo.

 

--------

 

please experiment with these suggestions. for me to do this for you would take a bit more time than i currently have.

 

once you have made some adjustments you can post an fla with just the mc and the key interactions and it will help us trouble shoot it further.

 

Carl

 

 

ps. your game looks like it is really coming along. nice job!

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...