I would like to check whether a tween I’m using has completed. Is there way check on progress, or completion?
I’ve looked through the actuate code, but nothing leapt out.
I would like to check whether a tween I’m using has completed. Is there way check on progress, or completion?
I’ve looked through the actuate code, but nothing leapt out.
var us:Sprite = new Sprite();
var there:Float = 256;
var areWeThereYet:Bool = false;
Actuate.tween(us, 50, {x:there}).onComplete(function():Void {
areWeThereYet = true;
trace("Yay!");
});
Thanks for that, I was aware of onComplete, but I don’t think I can use it in the way I want. I need to be able to overwrite the original tween using an awareness of the currently incomplete tween:
// psuedo code
var t:Tween; // I think this maybe simpleActuator...
var l:Float = 1;
if (t.inProgress)
{
l += t.timeRemaining;
}
t = Actuate.tween(sprite, l, {x:newX, y:newY});
I’m fairly certain there must be properties of the tween that can be used in this way, but I can’t see precisely how to make it work.
https://github.com/openfl/actuate/blob/master/motion/actuators/SimpleActuator.hx#L410
To get the time remaining, just rearrange those values a bit:
var timeRemaining:Float = duration - (currentTime - timeOffset);
Also, replace “currentTime
” with “Lib.getTimer() / 1000
.”
Thanks @player_03.
But, I’m not 100% sure what you’re suggesting.
All the variables in the SimpleActuator class are private - so is your idea to modify it?
also, I’ve not been able to use a variable to access the tween
var tween:SimpleActuator
or
var tween:GenericActuator
refuses to work for me… although I guess that isn’t the root of this problem.
//tween() returns a SimpleActuator unless you specifically tell it not to,
//so an unsafe cast is fine here.
var tween:SimpleActuator<Sprite, Sprite> = cast Actuate.tween(sprite, l, {x:newX, y:newY});
//In Haxe, it's really easy to get around privacy restrictions.
@:privateAccess
var timeRemaining:Float = tween.duration - (Lib.getTimer() / 1000 - tween.timeOffset);