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

Recommended Posts

Hi folks!

Iam making a platform game, where the Hero can get extra time for picking up some jewel!

For time tracking i'm using TweenMax.

Is there any way, to pause tween, and skip back(reverse) let's say with 5 seconds?

Any help appreciated!

tnx

daniel

Share on other sites

Certainly. With TweenMax you have access to a tween's currentTime, you could pause the tween and jump to 5 seconds prior to the current time like so

```
//the tween you want to control
var tween:TweenMax = TweenMax.to(mc, 10, {x:500});

//to jump back 5 seconds:
tween.pause();
tween.currentTime -= 5; //subtract 5 seconds from currentTime.
```

Also you can tween a tween's currentTime as well to have it smoothly play backwards for 5 seconds

`TweenLite.to(tween, .5, {currentTime:"-5"});`

note, the code above is for v11. In v12 the time() method replaces the currentTime property.

• 1
Share on other sites

brilliant!

I will play around with this..

tnx Carl!

just one more thing...If im using onUpdate, and onUpdateParams...

and im listening let's say for an "x" property, is it possible to use the value only once?

like:

```TweenMax.to(mc, 10, {x:-180, ease:Linear.easeNone, onUpdate:xCheck, onUpdateParams:[mc.x]});
function xCheck(_x:Number){

if(Math.floor(_x) == -140){
//My Signal release only once
//or maybe I could use the currentTime instead of _x
}
}
```

I could do this with a bunch of Booleans...but im still searching for an easier and reliable way.

best wishes

daniel

Share on other sites

I don't know if I understand what you mean by "use the value only once?" do you mean that once _x == 140, don't do the onUpdate any more?

Keep in mind that with your current code, the mc.x value that you are using in your onUpdateParams does not change while the tween runs, it is recorded when the tween is created.

if you do:

```import com.greensock.*;

var t:TweenMax = TweenMax.to(mc, 2, {x:500, onUpdate:xCheck, onUpdateParams:[mc.x]});

function xCheck(_x:Number):void{
trace(_x);
}```

you will see _x is always the value that mc.x was when the tween started.

if you want to remove the onUpdate once a certain x value has been reached you can do something like

```var t:TweenMax = TweenMax.to(mc, 2, {x:500, onUpdate:xCheck, onUpdateParams:[mc]});

function xCheck(clip:DisplayObject):void{
trace("onUpdate running");
if(clip.x > 200){
trace("i have gone too far");
t.updateTo({onUpdate:null});
}
}```

Keep in mind that when running conditional logic in your onUpdate function that there is no way to guarantee that the x of mc will be exactly equal to a certain value. It is safer to check that x is within a range of your target value. Above I just checked to see if mc.x was greater than 200.

• 1
Share on other sites

True that! My bad! I tested out, and realized the [params] won't change!

Actually what i meant is that during an enter_frame event, or OnUpdate,

we are calling our function for example 30 times/ sec..so if we have something in this

function, that's running down also 30 times..

Im thinking something like a CuePoint, but in the TweenMax!

anyway in the end i came up with this:

```public function lifeHandler()
{
trace(timeTween.currentTime + " current time")

if (timeTween.currentTime > 5)
{
timeTween.currentTime -= 5;
}else
{
timeTween.currentTime = 0;
}
}

public function lifeStarter()
{
timeTween = new TweenMax(_tl.life_line, lifeSec, { x:Math.round(-300), ease:Linear.easeNone, onUpdate:ChangePatch});
}

private function ChangePatch()
{
_x = Math.floor(_tl.life_line.x);

if (_x >= -87 && _x <=0)
{
if (boychar == false)
{
//change Hero Path for boychar
//call the function once
}

boychar = true;
menchar = false;
oldchar = false;

}
if (_x <= -88 && _x >= -197)
{
if (menchar == false)
{
//change Hero Path for menchar
//call the function once
}

menchar = true;
boychar = false;
oldchar = false;
}

if (_x <= -198 && _x >=-300)
{
if (oldchar == false)
{
//change Hero Path for oldchar
//call the function once
}

menchar = false;
boychar = false;
oldchar = true;
}
}
```