From 081cc87a00db0865b1fb8a0a24ab075496222249 Mon Sep 17 00:00:00 2001 From: "Lars A. Doucet" Date: Thu, 24 Sep 2015 11:07:47 -0500 Subject: [PATCH 01/13] FlxTween: add .thenWait(), .thenTween(), and .thenWaitAndTween() functions for chaining --- flixel/tweens/misc/VarTween.hx | 131 +++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/flixel/tweens/misc/VarTween.hx b/flixel/tweens/misc/VarTween.hx index a25620a891..e0ac06e4c8 100644 --- a/flixel/tweens/misc/VarTween.hx +++ b/flixel/tweens/misc/VarTween.hx @@ -1,7 +1,10 @@ package flixel.tweens.misc; import flixel.tweens.FlxTween; +import flixel.tweens.misc.VarTween.ThenCommand; +import flixel.tweens.misc.VarTween.TweenData; import flixel.util.FlxArrayUtil; +import flixel.util.FlxTimer; /** * Tweens multiple numeric public properties of an Object simultaneously. @@ -14,6 +17,8 @@ class VarTween extends FlxTween private var _startValues:Array; private var _range:Array; + private var _thens:Array; + /** * Clean up references */ @@ -22,6 +27,7 @@ class VarTween extends FlxTween super.destroy(); _object = null; _properties = null; + _thens = null; } private function new(Options:TweenOptions) @@ -60,6 +66,117 @@ class VarTween extends FlxTween return this; } + /** + * After this tween has finished, wait this many seconds, then do the next chained "then" command + * @param Delay The number of seconds to wait + * @return + */ + public function thenWait(Delay:Float):VarTween + { + if (_thens == null) + { + _thens = []; + } + _thens.push(new ThenCommand(Delay, null)); + return this; + } + + /** + * After the first tween has finished, do this tween next + * Tweens numeric public properties of an Object. Shorthand for creating a VarTween, starting it and adding it to the TweenManager. + * Example: thenTween(Object, { x: 500, y: 350 }, 2.0, { ease: easeFunction, onStart: onStart, onUpdate: onUpdate, onComplete: onComplete, type: FlxTween.ONESHOT }); + * + * @param Object The object containing the properties to tween. + * @param Values An object containing key/value pairs of properties and target values. + * @param Duration Duration of the tween in seconds. + * @param Options An object containing key/value pairs of the following optional parameters: + * type Tween type. + * onStart Optional start callback function. + * onUpdate Optional update callback function. + * onComplete Optional completion callback function. + * ease Optional easer function. + * startDelay Seconds to wait until starting this tween, 0 by default. + * loopDelay Seconds to wait between loops of this tween, 0 by default. + * @return The added VarTween object. + */ + public function thenTween(Object:Dynamic, Values:Dynamic, Duration:Float = 1, ?Options:TweenOptions):VarTween + { + if (_thens == null) + { + _thens = []; + } + var tween = { object:Object, values:Values, duration:Duration, options:Options }; + _thens.push(new ThenCommand(0, tween)); + return this; + } + + /** + * After the first tween has finished, wait this many seconds, then do this tween next + * Tweens numeric public properties of an Object. Shorthand for creating a VarTween, starting it and adding it to the TweenManager. + * Example: thenWaitAndTween(5, Object, { x: 500, y: 350 }, 2.0, { ease: easeFunction, onStart: onStart, onUpdate: onUpdate, onComplete: onComplete, type: FlxTween.ONESHOT }); + * + * @param Delay The number of seconds to wait + * @param Object The object containing the properties to tween. + * @param Values An object containing key/value pairs of properties and target values. + * @param Duration Duration of the tween in seconds. + * @param Options An object containing key/value pairs of the following optional parameters: + * type Tween type. + * onStart Optional start callback function. + * onUpdate Optional update callback function. + * onComplete Optional completion callback function. + * ease Optional easer function. + * startDelay Seconds to wait until starting this tween, 0 by default. + * loopDelay Seconds to wait between loops of this tween, 0 by default. + * @return The added VarTween object. + */ + public function thenWaitAndTween(Delay:Float, Object:Dynamic, Values:Dynamic, Duration:Float = 1, ?Options:TweenOptions):VarTween + { + if (_thens == null) + { + _thens = []; + } + var tween = { object:Object, values:Values, duration:Duration, options:Options }; + _thens.push(new ThenCommand(Delay, null)); + _thens.push(new ThenCommand(0 , tween)); + return this; + } + + @:access(flixel.tweens.FlxTween) + override function onEnd():Void + { + super.onEnd(); + if (_thens != null && _thens.length > 0) + { + var then = _thens[0]; + var data = then.tween; + var tween = null; + + _thens.splice(0, 1); + + if (then.delay <= 0) + { + if (data != null) + { + doNextTween(data, _thens); + } + } + else + { + doNextTween( { object:this, values: { }, duration:then.delay, options:null }, _thens); + } + _thens = null; + } + } + + private function doNextTween(data:TweenData, thens:Array):Void + { + var tween = FlxTween.tween(data.object, data.values, data.duration, data.options); + if (thens != null) + { + tween._thens = _thens; + } + } + override private function update(elapsed:Float):Void { var delay:Float = (executions > 0) ? loopDelay : startDelay; @@ -121,3 +238,17 @@ class VarTween extends FlxTween } } } + +typedef TweenData = { object:Dynamic, values:Dynamic, duration:Float, options:TweenOptions }; + +class ThenCommand +{ + public var delay:Float; + public var tween:TweenData; + + public function new(delay:Float, tween:TweenData) + { + this.delay = delay; + this.tween = tween; + } +} From 076302f57816ea63348a40ee9524d1a8a74cf305 Mon Sep 17 00:00:00 2001 From: "Lars A. Doucet" Date: Thu, 1 Oct 2015 11:57:40 -0500 Subject: [PATCH 02/13] Refactor tween chaining --- flixel/tweens/FlxTween.hx | 257 ++++++++++++++++++++++++++++- flixel/tweens/misc/VarTween.hx | 124 -------------- flixel/util/typeLimit/OneOfNine.hx | 9 + 3 files changed, 263 insertions(+), 127 deletions(-) create mode 100644 flixel/util/typeLimit/OneOfNine.hx diff --git a/flixel/tweens/FlxTween.hx b/flixel/tweens/FlxTween.hx index 1dcf0fdbfd..95243660c6 100644 --- a/flixel/tweens/FlxTween.hx +++ b/flixel/tweens/FlxTween.hx @@ -4,6 +4,13 @@ import flixel.FlxG; import flixel.FlxObject; import flixel.FlxSprite; import flixel.tweens.FlxEase.EaseFunction; +import flixel.tweens.FlxTween.LinearMotionParams; +import flixel.tweens.FlxTween.NumTweenParams; +import flixel.tweens.FlxTween.QuadMotionParams; +import flixel.tweens.FlxTween.QuadPathParams; +import flixel.tweens.FlxTween.ThenCommand; +import flixel.tweens.FlxTween.TweenOptions; +import flixel.tweens.FlxTween.TweenType; import flixel.tweens.misc.AngleTween; import flixel.tweens.misc.ColorTween; import flixel.tweens.misc.NumTween; @@ -18,6 +25,7 @@ import flixel.util.FlxArrayUtil; import flixel.util.FlxColor; import flixel.util.FlxDestroyUtil.IFlxDestroyable; import flixel.math.FlxPoint; +import flixel.util.typeLimit.OneOfNine; class FlxTween implements IFlxDestroyable { @@ -373,7 +381,8 @@ class FlxTween implements IFlxDestroyable private var _delayToUse:Float = 0; private var _running:Bool = false; private var _waitingForRestart:Bool = false; - + private var _thens:Array; + /** * This function is called when tween is created, or recycled. */ @@ -406,8 +415,60 @@ class FlxTween implements IFlxDestroyable onUpdate = null; onComplete = null; ease = null; + _thens = null; } - + + /** + * After this tween has finished, do this tween next + * @param tweenType + * @param params + * @return + */ + + public function then(tweenType:TweenType, params:Dynamic):FlxTween + { + if (_thens == null) + { + _thens = []; + } + _thens.push(new ThenCommand(0, tweenType, params)); + return this; + } + + /** + * After this tween has finished, wait this many seconds, then do the next chained "then" command + * @param Delay The number of seconds to wait + * @return + */ + public function wait(Delay:Float):FlxTween + { + if (_thens == null) + { + _thens = []; + } + _thens.push(new ThenCommand(Delay, None_, null)); + return this; + } + + /** + * Add a delay and a chained tween in the same command + * @param Delay + * @param tweenType + * @param params + * @return + */ + public function waitThen(Delay:Float, tweenType:TweenType, params:TweenParams):FlxTween + { + if (_thens == null) + { + _thens = []; + } + + _thens.push(new ThenCommand(Delay, None_, null)); + _thens.push(new ThenCommand(0 , tweenType, params)); + return this; + } + private function update(elapsed:Float):Void { _secondsSinceStart += elapsed; @@ -523,6 +584,69 @@ class FlxTween implements IFlxDestroyable active = false; _running = false; finished = true; + + if (_thens != null && _thens.length > 0) + { + var then = _thens[0]; + + _thens.splice(0, 1); + + if (then.delay <= 0) + { + if (then.params != null) + { + doNextTween(then.type, then.params, _thens); + } + } + else + { + var params:NumTweenParams = { FromValue:0, ToValue:0, Duration:then.delay }; + doNextTween(NumTween_, params, _thens); + } + _thens = null; + } + } + + private function doNextTween(type:TweenType, data:TweenParams, thens:Array):Void + { + var tween:FlxTween = null; + switch(type) + { + case TweenType.AngleTween_: + var atp:AngleTweenParams = cast data; + tween = FlxTween.angle(atp.Sprite, atp.FromAngle, atp.ToAngle, atp.Duration, atp.Options); + case TweenType.CircularMotion_: + var cmp:CircularMotionParams = cast data; + tween = FlxTween.circularMotion(cmp.Object, cmp.CenterX, cmp.CenterY, cmp.Radius, cmp.Angle, cmp.Clockwise, cmp.DurationOrSpeed, cmp.UseDuration, cmp.Options); + case TweenType.ColorTween_: + var ctp:ColorTweenParams = cast data; + tween = FlxTween.color(ctp.Sprite, ctp.Duration, ctp.FromColor, ctp.ToColor, ctp.Options); + case TweenType.CubicMotion_: + var cmp:CubicMotionParams = cast data; + tween = FlxTween.cubicMotion(cmp.Object, cmp.FromX, cmp.FromY, cmp.aX, cmp.aY, cmp.bX, cmp.bY, cmp.ToX, cmp.ToY, cmp.Duration, cmp.Options); + case TweenType.LinearMotion_: + var lmp:LinearMotionParams = cast data; + tween = FlxTween.linearMotion(lmp.Object, lmp.FromX, lmp.FromY, lmp.ToX, lmp.ToY, lmp.DurationOrSpeed, lmp.UseDuration, lmp.Options); + case TweenType.NumTween_: + var ntp:NumTweenParams = cast data; + tween = FlxTween.num(ntp.FromValue, ntp.ToValue, ntp.Duration, ntp.Options, ntp.TweenFunction); + case TweenType.QuadMotion_: + var qmp:QuadMotionParams = cast data; + tween = FlxTween.quadMotion(qmp.Object, qmp.FromX, qmp.FromY, qmp.ControlX, qmp.ControlY, qmp.ToX, qmp.ToY, qmp.DurationOrSpeed, qmp.UseDuration, qmp.Options); + case TweenType.QuadPath_: + var qpp:QuadPathParams = cast data; + tween = FlxTween.quadPath(qpp.Object, qpp.Points, qpp.DurationOrSpeed, qpp.UseDuration, qpp.Options); + case TweenType.VarTween_: + var vtp:VarTweenParams = cast data; + tween = FlxTween.tween(vtp.Object, vtp.Values, vtp.Duration, vtp.Options); + case TweenType.None_: + //do nothing + } + + if (thens != null) + { + tween._thens = _thens; + } } /** @@ -621,7 +745,120 @@ typedef TweenOptions = { ?onUpdate:TweenCallback, ?onComplete:TweenCallback, ?startDelay:Null, - ?loopDelay:Null, + ?loopDelay:Null +} + +typedef VarTweenParams = { + Object:Dynamic, + Values:Dynamic, + ?Duration:Float, + ?Options:TweenOptions +} + +typedef NumTweenParams = { + FromValue:Float, + ToValue:Float, + Duration:Float, + ?Options:TweenOptions, + ?TweenFunction:Float->Void +} + +typedef AngleTweenParams = { + ?Sprite:FlxSprite, + FromAngle:Float, + ToAngle:Float, + ?Duration:Float, + ?Options:TweenOptions +} + +typedef ColorTweenParams = { + ?Sprite:FlxSprite, + ?Duration:Float, + FromColor:FlxColor, + ToColor:FlxColor, + ?Options:TweenOptions +} + +typedef LinearMotionParams = { + Object:FlxObject, + FromX:Float, + FromY:Float, + ToX:Float, + ToY:Float, + ?DurationOrSpeed:Float, + ?UseDuration:Bool, + ?Options:TweenOptions +} + +typedef QuadMotionParams = { + Object:FlxObject, + FromX:Float, + FromY:Float, + ControlX:Float, + ControlY:Float, + ToX:Float, + ToY:Float, + ?DurationOrSpeed:Float, + UseDuration:Bool, + ?Options:TweenOptions +} + +typedef CubicMotionParams = { + Object:FlxObject, + FromX:Float, + FromY:Float, + aX:Float, + aY:Float, + bX:Float, + bY:Float, + ToX:Float, + ToY:Float, + ?Duration:Float, + ?Options:TweenOptions +} + +typedef CircularMotionParams = { + Object:FlxObject, + CenterX:Float, + CenterY:Float, + Radius:Float, + Angle:Float, + Clockwise:Bool, + ?DurationOrSpeed:Float, + ?UseDuration:Bool, + ?Options:TweenOptions +} + +typedef LinearPathOptions = { + Object:FlxObject, + Points:Array, + ?DurationOrSpeed:Float, + ?UseDuration:Bool, + ?Options:TweenOptions +} + +typedef QuadPathParams = { + Object:FlxObject, + Points:Array, + ?DurationOrSpeed:Float, + ?UseDuration:Bool, + ?Options:TweenOptions +} + +typedef TweenParams = OneOfNine; + +enum TweenType +{ + None_; + AngleTween_; + ColorTween_; + NumTween_; + VarTween_; + CircularMotion_; + CubicMotion_; + LinearMotion_; + QuadMotion_; + QuadPath_; } @:access(flixel.tweens.FlxTween) @@ -735,3 +972,17 @@ class FlxTweenManager extends FlxBasic } } } + +class ThenCommand +{ + public var delay:Float; + public var type:TweenType; + public var params:TweenParams; + + public function new(Delay:Float, Type:TweenType, Params:TweenParams) + { + type = Type; + delay = Delay; + params = Params; + } +} \ No newline at end of file diff --git a/flixel/tweens/misc/VarTween.hx b/flixel/tweens/misc/VarTween.hx index e0ac06e4c8..928f5f8919 100644 --- a/flixel/tweens/misc/VarTween.hx +++ b/flixel/tweens/misc/VarTween.hx @@ -1,8 +1,6 @@ package flixel.tweens.misc; import flixel.tweens.FlxTween; -import flixel.tweens.misc.VarTween.ThenCommand; -import flixel.tweens.misc.VarTween.TweenData; import flixel.util.FlxArrayUtil; import flixel.util.FlxTimer; @@ -17,8 +15,6 @@ class VarTween extends FlxTween private var _startValues:Array; private var _range:Array; - private var _thens:Array; - /** * Clean up references */ @@ -27,7 +23,6 @@ class VarTween extends FlxTween super.destroy(); _object = null; _properties = null; - _thens = null; } private function new(Options:TweenOptions) @@ -66,115 +61,10 @@ class VarTween extends FlxTween return this; } - /** - * After this tween has finished, wait this many seconds, then do the next chained "then" command - * @param Delay The number of seconds to wait - * @return - */ - public function thenWait(Delay:Float):VarTween - { - if (_thens == null) - { - _thens = []; - } - _thens.push(new ThenCommand(Delay, null)); - return this; - } - - /** - * After the first tween has finished, do this tween next - * Tweens numeric public properties of an Object. Shorthand for creating a VarTween, starting it and adding it to the TweenManager. - * Example: thenTween(Object, { x: 500, y: 350 }, 2.0, { ease: easeFunction, onStart: onStart, onUpdate: onUpdate, onComplete: onComplete, type: FlxTween.ONESHOT }); - * - * @param Object The object containing the properties to tween. - * @param Values An object containing key/value pairs of properties and target values. - * @param Duration Duration of the tween in seconds. - * @param Options An object containing key/value pairs of the following optional parameters: - * type Tween type. - * onStart Optional start callback function. - * onUpdate Optional update callback function. - * onComplete Optional completion callback function. - * ease Optional easer function. - * startDelay Seconds to wait until starting this tween, 0 by default. - * loopDelay Seconds to wait between loops of this tween, 0 by default. - * @return The added VarTween object. - */ - public function thenTween(Object:Dynamic, Values:Dynamic, Duration:Float = 1, ?Options:TweenOptions):VarTween - { - if (_thens == null) - { - _thens = []; - } - var tween = { object:Object, values:Values, duration:Duration, options:Options }; - _thens.push(new ThenCommand(0, tween)); - return this; - } - - /** - * After the first tween has finished, wait this many seconds, then do this tween next - * Tweens numeric public properties of an Object. Shorthand for creating a VarTween, starting it and adding it to the TweenManager. - * Example: thenWaitAndTween(5, Object, { x: 500, y: 350 }, 2.0, { ease: easeFunction, onStart: onStart, onUpdate: onUpdate, onComplete: onComplete, type: FlxTween.ONESHOT }); - * - * @param Delay The number of seconds to wait - * @param Object The object containing the properties to tween. - * @param Values An object containing key/value pairs of properties and target values. - * @param Duration Duration of the tween in seconds. - * @param Options An object containing key/value pairs of the following optional parameters: - * type Tween type. - * onStart Optional start callback function. - * onUpdate Optional update callback function. - * onComplete Optional completion callback function. - * ease Optional easer function. - * startDelay Seconds to wait until starting this tween, 0 by default. - * loopDelay Seconds to wait between loops of this tween, 0 by default. - * @return The added VarTween object. - */ - public function thenWaitAndTween(Delay:Float, Object:Dynamic, Values:Dynamic, Duration:Float = 1, ?Options:TweenOptions):VarTween - { - if (_thens == null) - { - _thens = []; - } - var tween = { object:Object, values:Values, duration:Duration, options:Options }; - _thens.push(new ThenCommand(Delay, null)); - _thens.push(new ThenCommand(0 , tween)); - return this; - } - @:access(flixel.tweens.FlxTween) override function onEnd():Void { super.onEnd(); - if (_thens != null && _thens.length > 0) - { - var then = _thens[0]; - var data = then.tween; - var tween = null; - - _thens.splice(0, 1); - - if (then.delay <= 0) - { - if (data != null) - { - doNextTween(data, _thens); - } - } - else - { - doNextTween( { object:this, values: { }, duration:then.delay, options:null }, _thens); - } - _thens = null; - } - } - - private function doNextTween(data:TweenData, thens:Array):Void - { - var tween = FlxTween.tween(data.object, data.values, data.duration, data.options); - if (thens != null) - { - tween._thens = _thens; - } } override private function update(elapsed:Float):Void @@ -238,17 +128,3 @@ class VarTween extends FlxTween } } } - -typedef TweenData = { object:Dynamic, values:Dynamic, duration:Float, options:TweenOptions }; - -class ThenCommand -{ - public var delay:Float; - public var tween:TweenData; - - public function new(delay:Float, tween:TweenData) - { - this.delay = delay; - this.tween = tween; - } -} diff --git a/flixel/util/typeLimit/OneOfNine.hx b/flixel/util/typeLimit/OneOfNine.hx new file mode 100644 index 0000000000..e56d33f45b --- /dev/null +++ b/flixel/util/typeLimit/OneOfNine.hx @@ -0,0 +1,9 @@ +package flixel.util.typeLimit; + +/** + * Useful to limit a Dynamic function argument's type to the specified + * type parameters. This does NOT make the use of Dynamic type-safe in + * any way (the underlying type is still Dynamic and Std.is() checks + + * casts are necessary). + */ +abstract OneOfNine(Dynamic) from T1 from T2 from T3 from T4 from T5 from T6 from T7 from T8 from T9 to T1 to T2 to T3 to T4 to T5 to T6 to T7 to T8 to T9{} \ No newline at end of file From 17459f8f6962cc3b1880ff884615f68cfc7744a9 Mon Sep 17 00:00:00 2001 From: "Lars A. Doucet" Date: Thu, 1 Oct 2015 11:59:14 -0500 Subject: [PATCH 03/13] tweak --- flixel/tweens/FlxTween.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flixel/tweens/FlxTween.hx b/flixel/tweens/FlxTween.hx index 95243660c6..60d595cc30 100644 --- a/flixel/tweens/FlxTween.hx +++ b/flixel/tweens/FlxTween.hx @@ -457,7 +457,7 @@ class FlxTween implements IFlxDestroyable * @param params * @return */ - public function waitThen(Delay:Float, tweenType:TweenType, params:TweenParams):FlxTween + public function waitThen(Delay:Float, tweenType:TweenType, params:Dynamic):FlxTween { if (_thens == null) { From c7c5bcfb02b4fe9c3a3170df5efdb86955541efe Mon Sep 17 00:00:00 2001 From: "Lars A. Doucet" Date: Thu, 1 Oct 2015 13:12:56 -0500 Subject: [PATCH 04/13] TweenType --> TweenMethod --- flixel/tweens/FlxTween.hx | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/flixel/tweens/FlxTween.hx b/flixel/tweens/FlxTween.hx index 60d595cc30..99fdbeda72 100644 --- a/flixel/tweens/FlxTween.hx +++ b/flixel/tweens/FlxTween.hx @@ -10,7 +10,7 @@ import flixel.tweens.FlxTween.QuadMotionParams; import flixel.tweens.FlxTween.QuadPathParams; import flixel.tweens.FlxTween.ThenCommand; import flixel.tweens.FlxTween.TweenOptions; -import flixel.tweens.FlxTween.TweenType; +import flixel.tweens.FlxTween.TweenMethod; import flixel.tweens.misc.AngleTween; import flixel.tweens.misc.ColorTween; import flixel.tweens.misc.NumTween; @@ -425,7 +425,7 @@ class FlxTween implements IFlxDestroyable * @return */ - public function then(tweenType:TweenType, params:Dynamic):FlxTween + public function then(tweenType:TweenMethod, params:Dynamic):FlxTween { if (_thens == null) { @@ -457,7 +457,7 @@ class FlxTween implements IFlxDestroyable * @param params * @return */ - public function waitThen(Delay:Float, tweenType:TweenType, params:Dynamic):FlxTween + public function waitThen(Delay:Float, tweenType:TweenMethod, params:Dynamic):FlxTween { if (_thens == null) { @@ -607,39 +607,39 @@ class FlxTween implements IFlxDestroyable } } - private function doNextTween(type:TweenType, data:TweenParams, thens:Array):Void + private function doNextTween(type:TweenMethod, data:TweenParams, thens:Array):Void { var tween:FlxTween = null; switch(type) { - case TweenType.AngleTween_: + case TweenMethod.AngleTween_: var atp:AngleTweenParams = cast data; tween = FlxTween.angle(atp.Sprite, atp.FromAngle, atp.ToAngle, atp.Duration, atp.Options); - case TweenType.CircularMotion_: + case TweenMethod.CircularMotion_: var cmp:CircularMotionParams = cast data; tween = FlxTween.circularMotion(cmp.Object, cmp.CenterX, cmp.CenterY, cmp.Radius, cmp.Angle, cmp.Clockwise, cmp.DurationOrSpeed, cmp.UseDuration, cmp.Options); - case TweenType.ColorTween_: + case TweenMethod.ColorTween_: var ctp:ColorTweenParams = cast data; tween = FlxTween.color(ctp.Sprite, ctp.Duration, ctp.FromColor, ctp.ToColor, ctp.Options); - case TweenType.CubicMotion_: + case TweenMethod.CubicMotion_: var cmp:CubicMotionParams = cast data; tween = FlxTween.cubicMotion(cmp.Object, cmp.FromX, cmp.FromY, cmp.aX, cmp.aY, cmp.bX, cmp.bY, cmp.ToX, cmp.ToY, cmp.Duration, cmp.Options); - case TweenType.LinearMotion_: + case TweenMethod.LinearMotion_: var lmp:LinearMotionParams = cast data; tween = FlxTween.linearMotion(lmp.Object, lmp.FromX, lmp.FromY, lmp.ToX, lmp.ToY, lmp.DurationOrSpeed, lmp.UseDuration, lmp.Options); - case TweenType.NumTween_: + case TweenMethod.NumTween_: var ntp:NumTweenParams = cast data; tween = FlxTween.num(ntp.FromValue, ntp.ToValue, ntp.Duration, ntp.Options, ntp.TweenFunction); - case TweenType.QuadMotion_: + case TweenMethod.QuadMotion_: var qmp:QuadMotionParams = cast data; tween = FlxTween.quadMotion(qmp.Object, qmp.FromX, qmp.FromY, qmp.ControlX, qmp.ControlY, qmp.ToX, qmp.ToY, qmp.DurationOrSpeed, qmp.UseDuration, qmp.Options); - case TweenType.QuadPath_: + case TweenMethod.QuadPath_: var qpp:QuadPathParams = cast data; tween = FlxTween.quadPath(qpp.Object, qpp.Points, qpp.DurationOrSpeed, qpp.UseDuration, qpp.Options); - case TweenType.VarTween_: + case TweenMethod.VarTween_: var vtp:VarTweenParams = cast data; tween = FlxTween.tween(vtp.Object, vtp.Values, vtp.Duration, vtp.Options); - case TweenType.None_: + case TweenMethod.None_: //do nothing } @@ -847,7 +847,7 @@ typedef QuadPathParams = { typedef TweenParams = OneOfNine; -enum TweenType +enum TweenMethod { None_; AngleTween_; @@ -976,10 +976,10 @@ class FlxTweenManager extends FlxBasic class ThenCommand { public var delay:Float; - public var type:TweenType; + public var type:TweenMethod; public var params:TweenParams; - public function new(Delay:Float, Type:TweenType, Params:TweenParams) + public function new(Delay:Float, Type:TweenMethod, Params:TweenParams) { type = Type; delay = Delay; From fcac08391b980df48ed2ffc0a56fd8cd085293c2 Mon Sep 17 00:00:00 2001 From: "Lars A. Doucet" Date: Thu, 1 Oct 2015 14:14:02 -0500 Subject: [PATCH 05/13] Cleanup tween chains --- flixel/tweens/FlxTween.hx | 90 +++++++++++++-------------------------- 1 file changed, 30 insertions(+), 60 deletions(-) diff --git a/flixel/tweens/FlxTween.hx b/flixel/tweens/FlxTween.hx index 99fdbeda72..52ff928eec 100644 --- a/flixel/tweens/FlxTween.hx +++ b/flixel/tweens/FlxTween.hx @@ -420,18 +420,19 @@ class FlxTween implements IFlxDestroyable /** * After this tween has finished, do this tween next - * @param tweenType + * @param method * @param params * @return */ - public function then(tweenType:TweenMethod, params:Dynamic):FlxTween + public function then(Tween:FlxTween):FlxTween { + Tween.cancel(); if (_thens == null) { _thens = []; } - _thens.push(new ThenCommand(0, tweenType, params)); + _thens.push(new ThenCommand(0, Tween)); return this; } @@ -446,26 +447,26 @@ class FlxTween implements IFlxDestroyable { _thens = []; } - _thens.push(new ThenCommand(Delay, None_, null)); + _thens.push(new ThenCommand(Delay, null)); return this; } /** * Add a delay and a chained tween in the same command * @param Delay - * @param tweenType + * @param method * @param params * @return */ - public function waitThen(Delay:Float, tweenType:TweenMethod, params:Dynamic):FlxTween + public function waitThen(Delay:Float, Tween:FlxTween):FlxTween { if (_thens == null) { _thens = []; } - _thens.push(new ThenCommand(Delay, None_, null)); - _thens.push(new ThenCommand(0 , tweenType, params)); + _thens.push(new ThenCommand(Delay, null)); + _thens.push(new ThenCommand(0 , Tween)); return this; } @@ -593,56 +594,27 @@ class FlxTween implements IFlxDestroyable if (then.delay <= 0) { - if (then.params != null) + if (then.tween != null) { - doNextTween(then.type, then.params, _thens); + doNextTween(then.tween, _thens); } } else { - var params:NumTweenParams = { FromValue:0, ToValue:0, Duration:then.delay }; - doNextTween(NumTween_, params, _thens); + var numTween = new NumTween(null); + numTween.tween(0, 0, then.delay); + doNextTween(numTween, _thens); } _thens = null; } } - private function doNextTween(type:TweenMethod, data:TweenParams, thens:Array):Void + private function doNextTween(tween:FlxTween, thens:Array):Void { - var tween:FlxTween = null; - switch(type) + if (!tween.active) { - case TweenMethod.AngleTween_: - var atp:AngleTweenParams = cast data; - tween = FlxTween.angle(atp.Sprite, atp.FromAngle, atp.ToAngle, atp.Duration, atp.Options); - case TweenMethod.CircularMotion_: - var cmp:CircularMotionParams = cast data; - tween = FlxTween.circularMotion(cmp.Object, cmp.CenterX, cmp.CenterY, cmp.Radius, cmp.Angle, cmp.Clockwise, cmp.DurationOrSpeed, cmp.UseDuration, cmp.Options); - case TweenMethod.ColorTween_: - var ctp:ColorTweenParams = cast data; - tween = FlxTween.color(ctp.Sprite, ctp.Duration, ctp.FromColor, ctp.ToColor, ctp.Options); - case TweenMethod.CubicMotion_: - var cmp:CubicMotionParams = cast data; - tween = FlxTween.cubicMotion(cmp.Object, cmp.FromX, cmp.FromY, cmp.aX, cmp.aY, cmp.bX, cmp.bY, cmp.ToX, cmp.ToY, cmp.Duration, cmp.Options); - case TweenMethod.LinearMotion_: - var lmp:LinearMotionParams = cast data; - tween = FlxTween.linearMotion(lmp.Object, lmp.FromX, lmp.FromY, lmp.ToX, lmp.ToY, lmp.DurationOrSpeed, lmp.UseDuration, lmp.Options); - case TweenMethod.NumTween_: - var ntp:NumTweenParams = cast data; - tween = FlxTween.num(ntp.FromValue, ntp.ToValue, ntp.Duration, ntp.Options, ntp.TweenFunction); - case TweenMethod.QuadMotion_: - var qmp:QuadMotionParams = cast data; - tween = FlxTween.quadMotion(qmp.Object, qmp.FromX, qmp.FromY, qmp.ControlX, qmp.ControlY, qmp.ToX, qmp.ToY, qmp.DurationOrSpeed, qmp.UseDuration, qmp.Options); - case TweenMethod.QuadPath_: - var qpp:QuadPathParams = cast data; - tween = FlxTween.quadPath(qpp.Object, qpp.Points, qpp.DurationOrSpeed, qpp.UseDuration, qpp.Options); - case TweenMethod.VarTween_: - var vtp:VarTweenParams = cast data; - tween = FlxTween.tween(vtp.Object, vtp.Values, vtp.Duration, vtp.Options); - case TweenMethod.None_: - //do nothing + tween.start(); } - if (thens != null) { tween._thens = _thens; @@ -849,16 +821,16 @@ typedef TweenParams = OneOfNine Date: Thu, 1 Oct 2015 14:27:06 -0500 Subject: [PATCH 06/13] FlxTween: finish cleanup --- flixel/tweens/FlxTween.hx | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/flixel/tweens/FlxTween.hx b/flixel/tweens/FlxTween.hx index 52ff928eec..5735f78b07 100644 --- a/flixel/tweens/FlxTween.hx +++ b/flixel/tweens/FlxTween.hx @@ -427,7 +427,7 @@ class FlxTween implements IFlxDestroyable public function then(Tween:FlxTween):FlxTween { - Tween.cancel(); + Tween.cancelSoft(); if (_thens == null) { _thens = []; @@ -534,6 +534,14 @@ class FlxTween implements IFlxDestroyable manager.remove(this); } + private function cancelSoft():Void + { + active = false; + _running = false; + finished = true; + manager.removeSoft(this); + } + private function finish():Void { executions++; @@ -601,9 +609,7 @@ class FlxTween implements IFlxDestroyable } else { - var numTween = new NumTween(null); - numTween.tween(0, 0, then.delay); - doNextTween(numTween, _thens); + doNextTween(FlxTween.num(0,0,then.delay), _thens); } _thens = null; } @@ -614,6 +620,7 @@ class FlxTween implements IFlxDestroyable if (!tween.active) { tween.start(); + manager.add(tween); } if (thens != null) { @@ -914,7 +921,6 @@ class FlxTweenManager extends FlxBasic * Remove a FlxTween. * * @param Tween The FlxTween to remove. - * @param Destroy Whether you want to destroy the FlxTween. * @return The added FlxTween object. */ @:allow(flixel.tweens.FlxTween) @@ -932,6 +938,28 @@ class FlxTweenManager extends FlxBasic return Tween; } + + /** + * Remove a FlxTween without destroying it + * + * @param Tween The FlxTween to remove. + * @param Destroy Whether you want to destroy the FlxTween. + * @return The added FlxTween object. + */ + @:allow(flixel.tweens.FlxTween) + private function removeSoft(Tween:FlxTween):FlxTween + { + if (Tween == null) + { + return null; + } + + Tween.active = false; + + FlxArrayUtil.fastSplice(_tweens, Tween); + + return Tween; + } /** * Removes all FlxTweens. From d9cd03197568054e1cd2bdfb7215d62b3d1b349e Mon Sep 17 00:00:00 2001 From: "Lars A. Doucet" Date: Thu, 1 Oct 2015 15:11:31 -0500 Subject: [PATCH 07/13] Flxtween cleanup --- flixel/tweens/FlxTween.hx | 118 ----------------------------- flixel/util/typeLimit/OneOfNine.hx | 9 --- 2 files changed, 127 deletions(-) delete mode 100644 flixel/util/typeLimit/OneOfNine.hx diff --git a/flixel/tweens/FlxTween.hx b/flixel/tweens/FlxTween.hx index 5735f78b07..9a68ac2ea9 100644 --- a/flixel/tweens/FlxTween.hx +++ b/flixel/tweens/FlxTween.hx @@ -4,10 +4,6 @@ import flixel.FlxG; import flixel.FlxObject; import flixel.FlxSprite; import flixel.tweens.FlxEase.EaseFunction; -import flixel.tweens.FlxTween.LinearMotionParams; -import flixel.tweens.FlxTween.NumTweenParams; -import flixel.tweens.FlxTween.QuadMotionParams; -import flixel.tweens.FlxTween.QuadPathParams; import flixel.tweens.FlxTween.ThenCommand; import flixel.tweens.FlxTween.TweenOptions; import flixel.tweens.FlxTween.TweenMethod; @@ -25,7 +21,6 @@ import flixel.util.FlxArrayUtil; import flixel.util.FlxColor; import flixel.util.FlxDestroyUtil.IFlxDestroyable; import flixel.math.FlxPoint; -import flixel.util.typeLimit.OneOfNine; class FlxTween implements IFlxDestroyable { @@ -727,119 +722,6 @@ typedef TweenOptions = { ?loopDelay:Null } -typedef VarTweenParams = { - Object:Dynamic, - Values:Dynamic, - ?Duration:Float, - ?Options:TweenOptions -} - -typedef NumTweenParams = { - FromValue:Float, - ToValue:Float, - Duration:Float, - ?Options:TweenOptions, - ?TweenFunction:Float->Void -} - -typedef AngleTweenParams = { - ?Sprite:FlxSprite, - FromAngle:Float, - ToAngle:Float, - ?Duration:Float, - ?Options:TweenOptions -} - -typedef ColorTweenParams = { - ?Sprite:FlxSprite, - ?Duration:Float, - FromColor:FlxColor, - ToColor:FlxColor, - ?Options:TweenOptions -} - -typedef LinearMotionParams = { - Object:FlxObject, - FromX:Float, - FromY:Float, - ToX:Float, - ToY:Float, - ?DurationOrSpeed:Float, - ?UseDuration:Bool, - ?Options:TweenOptions -} - -typedef QuadMotionParams = { - Object:FlxObject, - FromX:Float, - FromY:Float, - ControlX:Float, - ControlY:Float, - ToX:Float, - ToY:Float, - ?DurationOrSpeed:Float, - UseDuration:Bool, - ?Options:TweenOptions -} - -typedef CubicMotionParams = { - Object:FlxObject, - FromX:Float, - FromY:Float, - aX:Float, - aY:Float, - bX:Float, - bY:Float, - ToX:Float, - ToY:Float, - ?Duration:Float, - ?Options:TweenOptions -} - -typedef CircularMotionParams = { - Object:FlxObject, - CenterX:Float, - CenterY:Float, - Radius:Float, - Angle:Float, - Clockwise:Bool, - ?DurationOrSpeed:Float, - ?UseDuration:Bool, - ?Options:TweenOptions -} - -typedef LinearPathOptions = { - Object:FlxObject, - Points:Array, - ?DurationOrSpeed:Float, - ?UseDuration:Bool, - ?Options:TweenOptions -} - -typedef QuadPathParams = { - Object:FlxObject, - Points:Array, - ?DurationOrSpeed:Float, - ?UseDuration:Bool, - ?Options:TweenOptions -} - -typedef TweenParams = OneOfNine; - -enum TweenMethod -{ - None; - AngleTween; - ColorTween; - NumTween; - VarTween; - CircularMotion; - CubicMotion; - LinearMotion; - QuadMotion; - QuadPath; -} - @:access(flixel.tweens.FlxTween) class FlxTweenManager extends FlxBasic { diff --git a/flixel/util/typeLimit/OneOfNine.hx b/flixel/util/typeLimit/OneOfNine.hx deleted file mode 100644 index e56d33f45b..0000000000 --- a/flixel/util/typeLimit/OneOfNine.hx +++ /dev/null @@ -1,9 +0,0 @@ -package flixel.util.typeLimit; - -/** - * Useful to limit a Dynamic function argument's type to the specified - * type parameters. This does NOT make the use of Dynamic type-safe in - * any way (the underlying type is still Dynamic and Std.is() checks + - * casts are necessary). - */ -abstract OneOfNine(Dynamic) from T1 from T2 from T3 from T4 from T5 from T6 from T7 from T8 from T9 to T1 to T2 to T3 to T4 to T5 to T6 to T7 to T8 to T9{} \ No newline at end of file From 7cb4464d2df00fdefe732f3fcac7272fb4e445a7 Mon Sep 17 00:00:00 2001 From: "Lars A. Doucet" Date: Thu, 1 Oct 2015 15:27:41 -0500 Subject: [PATCH 08/13] FlxTween: missed one --- flixel/tweens/FlxTween.hx | 1 - 1 file changed, 1 deletion(-) diff --git a/flixel/tweens/FlxTween.hx b/flixel/tweens/FlxTween.hx index 9a68ac2ea9..9dd6636eea 100644 --- a/flixel/tweens/FlxTween.hx +++ b/flixel/tweens/FlxTween.hx @@ -6,7 +6,6 @@ import flixel.FlxSprite; import flixel.tweens.FlxEase.EaseFunction; import flixel.tweens.FlxTween.ThenCommand; import flixel.tweens.FlxTween.TweenOptions; -import flixel.tweens.FlxTween.TweenMethod; import flixel.tweens.misc.AngleTween; import flixel.tweens.misc.ColorTween; import flixel.tweens.misc.NumTween; From 92079498c4d9ab13dd20985c3a02afecfa17eeb5 Mon Sep 17 00:00:00 2001 From: "Lars A. Doucet" Date: Thu, 1 Oct 2015 15:28:32 -0500 Subject: [PATCH 09/13] FlxTween: remove waitThen() --- flixel/tweens/FlxTween.hx | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/flixel/tweens/FlxTween.hx b/flixel/tweens/FlxTween.hx index 9dd6636eea..9a105ee830 100644 --- a/flixel/tweens/FlxTween.hx +++ b/flixel/tweens/FlxTween.hx @@ -445,25 +445,6 @@ class FlxTween implements IFlxDestroyable return this; } - /** - * Add a delay and a chained tween in the same command - * @param Delay - * @param method - * @param params - * @return - */ - public function waitThen(Delay:Float, Tween:FlxTween):FlxTween - { - if (_thens == null) - { - _thens = []; - } - - _thens.push(new ThenCommand(Delay, null)); - _thens.push(new ThenCommand(0 , Tween)); - return this; - } - private function update(elapsed:Float):Void { _secondsSinceStart += elapsed; From ce1203b1cbab0486fd569f6e7c5ce243d4ad1fea Mon Sep 17 00:00:00 2001 From: "Lars A. Doucet" Date: Thu, 1 Oct 2015 15:29:39 -0500 Subject: [PATCH 10/13] FlxTween Fix docs --- flixel/tweens/FlxTween.hx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/flixel/tweens/FlxTween.hx b/flixel/tweens/FlxTween.hx index 9a105ee830..bc8b67e3f3 100644 --- a/flixel/tweens/FlxTween.hx +++ b/flixel/tweens/FlxTween.hx @@ -414,8 +414,7 @@ class FlxTween implements IFlxDestroyable /** * After this tween has finished, do this tween next - * @param method - * @param params + * @param Tween The FlxTween to run next * @return */ From 2626406191f7befd05f3f76219a44befaca2a98e Mon Sep 17 00:00:00 2001 From: "Lars A. Doucet" Date: Thu, 1 Oct 2015 15:57:43 -0500 Subject: [PATCH 11/13] Tween: fixes --- flixel/tweens/FlxTween.hx | 40 ++++++++-------------------------- flixel/tweens/misc/VarTween.hx | 6 ----- 2 files changed, 9 insertions(+), 37 deletions(-) diff --git a/flixel/tweens/FlxTween.hx b/flixel/tweens/FlxTween.hx index bc8b67e3f3..5e5a21476c 100644 --- a/flixel/tweens/FlxTween.hx +++ b/flixel/tweens/FlxTween.hx @@ -4,7 +4,7 @@ import flixel.FlxG; import flixel.FlxObject; import flixel.FlxSprite; import flixel.tweens.FlxEase.EaseFunction; -import flixel.tweens.FlxTween.ThenCommand; +import flixel.tweens.FlxTween.ChainedTween; import flixel.tweens.FlxTween.TweenOptions; import flixel.tweens.misc.AngleTween; import flixel.tweens.misc.ColorTween; @@ -375,7 +375,7 @@ class FlxTween implements IFlxDestroyable private var _delayToUse:Float = 0; private var _running:Bool = false; private var _waitingForRestart:Bool = false; - private var _thens:Array; + private var _thens:Array; /** * This function is called when tween is created, or recycled. @@ -425,7 +425,7 @@ class FlxTween implements IFlxDestroyable { _thens = []; } - _thens.push(new ThenCommand(0, Tween)); + _thens.push(new ChainedTween(0, Tween)); return this; } @@ -440,7 +440,7 @@ class FlxTween implements IFlxDestroyable { _thens = []; } - _thens.push(new ThenCommand(Delay, null)); + _thens.push(new ChainedTween(Delay, null)); return this; } @@ -513,7 +513,7 @@ class FlxTween implements IFlxDestroyable active = false; _running = false; finished = true; - manager.removeSoft(this); + manager.remove(this, false); } private function finish():Void @@ -589,7 +589,7 @@ class FlxTween implements IFlxDestroyable } } - private function doNextTween(tween:FlxTween, thens:Array):Void + private function doNextTween(tween:FlxTween, thens:Array):Void { if (!tween.active) { @@ -782,10 +782,11 @@ class FlxTweenManager extends FlxBasic * Remove a FlxTween. * * @param Tween The FlxTween to remove. + * @param Destroy Whether you want to destroy the FlxTween * @return The added FlxTween object. */ @:allow(flixel.tweens.FlxTween) - private function remove(Tween:FlxTween):FlxTween + private function remove(Tween:FlxTween, Destroy:Bool=true):FlxTween { if (Tween == null) { @@ -799,29 +800,6 @@ class FlxTweenManager extends FlxBasic return Tween; } - - /** - * Remove a FlxTween without destroying it - * - * @param Tween The FlxTween to remove. - * @param Destroy Whether you want to destroy the FlxTween. - * @return The added FlxTween object. - */ - @:allow(flixel.tweens.FlxTween) - private function removeSoft(Tween:FlxTween):FlxTween - { - if (Tween == null) - { - return null; - } - - Tween.active = false; - - FlxArrayUtil.fastSplice(_tweens, Tween); - - return Tween; - } - /** * Removes all FlxTweens. */ @@ -834,7 +812,7 @@ class FlxTweenManager extends FlxBasic } } -class ThenCommand +private class ChainedTween { public var delay:Float; public var tween:FlxTween; diff --git a/flixel/tweens/misc/VarTween.hx b/flixel/tweens/misc/VarTween.hx index 928f5f8919..f791ca8b23 100644 --- a/flixel/tweens/misc/VarTween.hx +++ b/flixel/tweens/misc/VarTween.hx @@ -61,12 +61,6 @@ class VarTween extends FlxTween return this; } - @:access(flixel.tweens.FlxTween) - override function onEnd():Void - { - super.onEnd(); - } - override private function update(elapsed:Float):Void { var delay:Float = (executions > 0) ? loopDelay : startDelay; From bc2e2582a476624f779916308c50ee344d486682 Mon Sep 17 00:00:00 2001 From: "Lars A. Doucet" Date: Thu, 1 Oct 2015 16:47:33 -0500 Subject: [PATCH 12/13] FlxTween fixes --- flixel/tweens/FlxTween.hx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/flixel/tweens/FlxTween.hx b/flixel/tweens/FlxTween.hx index 5e5a21476c..2962b79445 100644 --- a/flixel/tweens/FlxTween.hx +++ b/flixel/tweens/FlxTween.hx @@ -4,7 +4,6 @@ import flixel.FlxG; import flixel.FlxObject; import flixel.FlxSprite; import flixel.tweens.FlxEase.EaseFunction; -import flixel.tweens.FlxTween.ChainedTween; import flixel.tweens.FlxTween.TweenOptions; import flixel.tweens.misc.AngleTween; import flixel.tweens.misc.ColorTween; @@ -580,6 +579,10 @@ class FlxTween implements IFlxDestroyable { doNextTween(then.tween, _thens); } + else + { + onEnd(); + } } else { @@ -794,7 +797,11 @@ class FlxTweenManager extends FlxBasic } Tween.active = false; - Tween.destroy(); + + if (Destroy) + { + Tween.destroy(); + } FlxArrayUtil.fastSplice(_tweens, Tween); From 9667598c64461c3f6868187656f244ac0174d17f Mon Sep 17 00:00:00 2001 From: "Lars A. Doucet" Date: Thu, 1 Oct 2015 16:52:27 -0500 Subject: [PATCH 13/13] Vartween: fix errant import --- flixel/tweens/misc/VarTween.hx | 1 - 1 file changed, 1 deletion(-) diff --git a/flixel/tweens/misc/VarTween.hx b/flixel/tweens/misc/VarTween.hx index f791ca8b23..a25620a891 100644 --- a/flixel/tweens/misc/VarTween.hx +++ b/flixel/tweens/misc/VarTween.hx @@ -2,7 +2,6 @@ package flixel.tweens.misc; import flixel.tweens.FlxTween; import flixel.util.FlxArrayUtil; -import flixel.util.FlxTimer; /** * Tweens multiple numeric public properties of an Object simultaneously.