From c923785a3cd7be01fa825a7874adc9cc810ecbf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20R=C3=B8nning?= Date: Wed, 21 Jan 2015 18:28:49 +0100 Subject: [PATCH] Added onUpdate callback (giving a normalized 0-1 value for tween progress) Removed buggy redundant check for debug builds --- tween/Delta.hx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tween/Delta.hx b/tween/Delta.hx index 9525d78..7dc833f 100644 --- a/tween/Delta.hx +++ b/tween/Delta.hx @@ -74,6 +74,7 @@ private class TweenAction { var totalDuration:Float; var prevPropCreated:Null; var onCompleteFunc:Null < Void->Void > ; + var onStepFunc:Null < Float->Void > ; var triggeringID:Null; var triggerID:Null; var triggerOnComplete:Bool; @@ -100,6 +101,11 @@ private class TweenAction { } } + public inline function onUpdate(func:Float->Void):TweenAction { + onStepFunc = func; + return this; + } + public inline function onComplete(func:Void->Void):TweenAction { onCompleteFunc = func; return this; @@ -149,10 +155,6 @@ private class TweenAction { public function prop(property:String, value:Float, duration:Float):TweenAction { if(properties==null) properties = new Map(); - #if debug - if (!Reflect.hasField(target, property)) throw 'No property "$property" on object'; - //TODO: Check if the field is a property or not and if so, warn - #end totalDuration = Math.max(totalDuration, duration); properties.set(property, prevPropCreated = new PropertyTween(this, property, value, duration)); return this; @@ -218,6 +220,9 @@ private class TweenAction { if (time >= totalDuration) { finish(); } + if (onStepFunc != null) { + onStepFunc(time / totalDuration); + } return this; } } @@ -306,6 +311,7 @@ class Delta } public static function tween(target:Dynamic):TweenAction { + if (target == null) throw "Cannot tween null target"; return createSequence(target).createAction(); }