Permalink
Browse files

motion: starting at custom keyframe changes/fixes

  • Loading branch information...
andrewfitz committed Nov 10, 2009
1 parent 66c36ec commit 1c5c502c348416c969d0e633700657a0d1825471
View
@@ -1,12 +1,16 @@
Desuade Library Changelog
-------------------------
-Motion Package 1.0 & Partigen 2.0 Final
+Motion Package 1.0 & Partigen 2.0 Final (2009/11/15)
Motion:
-changed: ease function/string/null conversions done in tween classes > BasicTween
-changed: primitiveTweens now strictly require ease functions, doesn't require Easing class
- -examples: added new MotionController example
+ -changed: moved sequence building in start() for MotionControllers, no need to rebuild sequence
+ -changed: controllers.start(keyframe = 'begin')
+ -examples: added new MotionController example and starting at custom keyframe example
+ -fix: starting a controller at a keyframe will now start at the correct value
+ -fix: makeEase function
Partigen:
-fix: emitters won't error out on stop() when they're not active
@@ -38,7 +38,7 @@ package com.desuade.motion {
/**
* The numeric version of the package. Used for version comparisions.
*/
- public static const VERSION:Number = 1.007;
+ public static const VERSION:Number = 1.008;
/**
* The "official" release version.
@@ -60,20 +60,21 @@ package com.desuade.motion.controllers {
/**
* @private
*/
- internal override function generateStartValue($target:Object, $property:String):* {
+ internal override function generateStartValue($target:Object, $property:String, $keyframe:String):* {
var nv:*;
- var nt:String = this['begin'].extras.type;
- if(this['begin'].value != null && this['begin'].value != 'none'){
- nv = (this['begin'].spread != '0') ? RandomColor.fromRange(this['begin'].value, this['begin'].spread) : this['begin'].value;
+ var bkf:Keyframe = this[$keyframe];
+ var nt:String = bkf.extras.type;
+ if(bkf.value != null && bkf.value != 'none'){
+ nv = (bkf.spread != '0') ? RandomColor.fromRange(bkf.value, bkf.spread) : bkf.value;
} else nt = 'clear';
- return ColorHelper.getColorObject(nt || 'tint', this['begin'].extras.amount || 1, nv, ($property == null) ? $target.transform.colorTransform : null);
+ return ColorHelper.getColorObject(nt || 'tint', bkf.extras.amount || 1, nv, ($property == null) ? $target.transform.colorTransform : null);
}
/**
* @private
*/
- internal override function setStartValue($target:Object, $property:String):void {
- var nvo:Object = generateStartValue($target, $property);
+ internal override function setStartValue($target:Object, $property:String, $keyframe:String):void {
+ var nvo:Object = generateStartValue($target, $property, $keyframe);
if($property == null){
$target.transform.colorTransform = new ColorTransform(nvo.redMultiplier, nvo.greenMultiplier, nvo.blueMultiplier, $target.alpha, nvo.redOffset, nvo.greenOffset, nvo.blueOffset);
} else {
@@ -126,7 +126,7 @@ package com.desuade.motion.controllers {
public function fromXML($xml:XML, $useposition:Boolean = true):Keyframe {
if($xml.@label != undefined) delete $xml.@label;
if($useposition) position = XMLHelper.dexmlize($xml.@position);
- ease = XMLHelper.dexmlize($xml.@ease);
+ ease = $xml.@ease;
if($xml.@value != undefined) value = XMLHelper.dexmlize($xml.@value);
spread = XMLHelper.dexmlize($xml.@spread);
delete $xml.@ease;
@@ -237,18 +237,19 @@ package com.desuade.motion.controllers {
/**
* @private
*/
- internal function generateStartValue($target:Object, $property:String):* {
+ internal function generateStartValue($target:Object, $property:String, $keyframe:String):* {
var nv:Number;
- if(this['begin'].value == null) nv = $target[$property];
- else nv = (typeof this['begin'].value == 'string') ? $target[$property] + Number(this['begin'].value) : this['begin'].value;
- return (this['begin'].spread !== '0') ? Random.fromRange(nv, ((typeof this['begin'].spread == 'string') ? nv + Number(this['begin'].spread) : this['begin'].spread), precision) : nv;
+ var bkf:Keyframe = this[$keyframe];
+ if(bkf.value == null) nv = $target[$property];
+ else nv = (typeof bkf.value == 'string') ? $target[$property] + Number(bkf.value) : bkf.value;
+ return (bkf.spread !== '0') ? Random.fromRange(nv, ((typeof bkf.spread == 'string') ? nv + Number(bkf.spread) : bkf.spread), precision) : nv;
}
/**
* @private
*/
- internal function setStartValue($target:Object, $property:String):void {
- $target[$property] = generateStartValue($target, $property);
+ internal function setStartValue($target:Object, $property:String, $keyframe:String):void {
+ $target[$property] = generateStartValue($target, $property, $keyframe);
}
/**
@@ -294,7 +295,7 @@ package com.desuade.motion.controllers {
} else nuv = nnnv;
}
var nv:Number = (np.spread !== '0') ? Random.fromRange(nuv, ((typeof np.spread == 'string') ? nuv + Number(np.spread) : np.spread), precision) : nuv;
- var tmo:Object = {target:$target, property:$property, value:nv, ease:np.ease, duration:calculateDuration($duration, this[pa[i-1]].position, np.position), delay:0};
+ var tmo:Object = {property:$property, value:nv, ease:np.ease, duration:calculateDuration($duration, this[pa[i-1]].position, np.position), delay:0};
for (var h:String in np.extras) {
tmo[h] = np.extras[h];
}
@@ -83,7 +83,7 @@ package com.desuade.motion.controllers {
/**
* @private
*/
- protected var _sequence:*;
+ protected var _sequence:* = null;
/**
* <p>Creates a new MotionController for the given target and property.</p>
@@ -128,17 +128,17 @@ package com.desuade.motion.controllers {
* Starts the controller. This will internally create a Sequence (of tweens) that will be ran to match the points in the controller's PointsContainer, running from 'begin' to 'end' points.
*
* @param keyframe The label of the keyframe to start at.
+ * @param rebuild Forces a rebuild of the internal sequence on start.
* @return The MotionController (for chaining)
*/
- public function start($keyframe:String = null):* {
- setStartValue();
- var ta:Array = keyframes.createTweens(target, property, duration);
+ public function start($keyframe:String = 'begin', $rebuild:Boolean = false):* {
+ //$keyframe = (keyframes[$keyframe] == undefined) ? 'begin' : $keyframe;
+ setStartValue($keyframe);
_active = true;
- _sequence = new ClassSequence(keyframes.tweenClass);
- _sequence.pushArray(ta);
+ if(_sequence == null || $rebuild) buildSequence();
_sequence.addEventListener(SequenceEvent.ENDED, tweenEnd, false, 0, false);
_sequence.addEventListener(SequenceEvent.ADVANCED, advance, false, 0, false);
- if($keyframe != null) _sequence.start(keyframes.getOrderedLabels().indexOf($keyframe));
+ if($keyframe != 'begin') _sequence.start(keyframes.getOrderedLabels().indexOf($keyframe));
else _sequence.start();
dispatchEvent(new ControllerEvent(ControllerEvent.STARTED, {controller:this}));
return this;
@@ -152,6 +152,15 @@ package com.desuade.motion.controllers {
else Debug.output('motion', 10003);
}
+ /**
+ * @private
+ */
+ protected function buildSequence():void {
+ _sequence = new ClassSequence(keyframes.tweenClass);
+ _sequence.overrides = {target:target};
+ _sequence.pushArray(keyframes.createTweens(target, property, duration));
+ }
+
/**
* This easily sets the 'begin' and 'end' keyframes of the controller to create a standard "one-shot" tween.
*
@@ -173,9 +182,11 @@ package com.desuade.motion.controllers {
/**
* This sets the initial start value of the target. This normally doesn't need to be called, as it is internally called everytime start() is.
+ *
+ * @param keyframe This is the label of the keyframe to generate a starting value from.
*/
- public function setStartValue():void {
- keyframes.setStartValue(target, property);
+ public function setStartValue($keyframe:String = 'begin'):void {
+ keyframes.setStartValue(target, property, $keyframe);
}
/**
@@ -167,7 +167,7 @@ package com.desuade.motion.controllers {
*
* @return The MultiController (for chaining)
*/
- public function start($keyframe:String = null):* {
+ public function start($keyframe:String = 'begin'):* {
for (var p:String in this){
this[p].start($keyframe);
}
@@ -135,23 +135,24 @@ package com.desuade.motion.controllers {
/**
* @inheritDoc
*/
- public override function start($keyframe:String = null):* {
+ public override function start($keyframe:String = 'begin'):* {
startPhysicsControllers($keyframe);
}
/**
* @private
*/
- protected function startPhysicsControllers($keyframe:String = null):void {
+ protected function startPhysicsControllers($keyframe:String):void {
+ //$keyframe = (keyframes[$keyframe] == undefined) ? 'begin' : $keyframe;
if(this.velocity.keyframes.isFlat()){
- this.velocity.setStartValue();
- if(this.acceleration.keyframes.isFlat()) this.acceleration.setStartValue();
+ this.velocity.setStartValue($keyframe);
+ if(this.acceleration.keyframes.isFlat()) this.acceleration.setStartValue($keyframe);
else this.acceleration.start($keyframe);
- if(this.friction.keyframes.isFlat()) this.friction.setStartValue();
+ if(this.friction.keyframes.isFlat()) this.friction.setStartValue($keyframe);
else this.friction.start($keyframe);
} else {
- this.acceleration.setStartValue();
- this.friction.setStartValue();
+ this.acceleration.setStartValue($keyframe);
+ this.friction.setStartValue($keyframe);
this.velocity.start($keyframe);
}
}
@@ -88,13 +88,9 @@ package com.desuade.motion.tweens {
* @private
*/
protected function makeEase($ease:*):Function {
- if($ease == null){
- return Easing.linear;
- } else if(typeof $ease == 'string'){
- return Easing[$ease];
- } else {
- return $ease;
- }
+ if(typeof $ease == 'string') return Easing[$ease];
+ else if(typeof $ease == 'function') return $ease;
+ else return Easing.linear;
}
}
Binary file not shown.

0 comments on commit 1c5c502

Please sign in to comment.