Permalink
Browse files

added hexProperty for ColorTween

  • Loading branch information...
1 parent 0cdf8fa commit a5cb13df58fd8e943c120388b8637943f8e2388b @andrewfitz committed Jun 27, 2009
View
@@ -0,0 +1,16 @@
+Desuade Library Changelog
+-------------------------
+
+Beta 2:
+
+ Motion:
+ -added hexProperty to BasicColorTween/ColorTween to allow for non-DisplayObject color tweening
+ -added debug codes for BasicPhysics
+
+ Partigen: none
+
+ Debugging: none
+
+ Utils: none
+
+Beta 1 (2009/6/22): initial release
@@ -62,6 +62,9 @@ package com.desuade.motion {
40006: "[Sequence] simulating new position at $", //removed
40007: "[Tween] starting tween at position: $",
40008: "[Sequence] sequence started",
+ 40009: "[Physics] new physics object created",
+ 40010: "[Physics] physics engine started",
+ 40011: "[Physics] physics engine stopped",
//primitive low level codes
50001: "[PrimitiveTween] tween started: $",
@@ -24,7 +24,8 @@ THE SOFTWARE.
package com.desuade.motion.physics {
- import flash.display.*;
+ import flash.display.*;
+ import com.desuade.debugging.*;
import flash.events.Event;
import flash.events.EventDispatcher;
@@ -106,7 +107,7 @@ package com.desuade.motion.physics {
*
* <p>Each BasicPhysics object controls a single property on a given target object, and applies basic physics equations to calculate a change in value.</p>
*
- * <p>Unlike tweens, there is no end value, and the BasicPhysics' update will continue to run until it is stopd.</p>
+ * <p>Unlike tweens, there is no end value, and the BasicPhysics' update will continue to run until it is stopped.</p>
*
* @param target The target object.
* @param property The property to apply the physics to.
@@ -131,6 +132,7 @@ package com.desuade.motion.physics {
friction = $friction;
flip = $flip;
angle = $angle;
+ Debug.output('motion', 40009);
}
/**
@@ -167,6 +169,7 @@ package com.desuade.motion.physics {
dispatchEvent(new PhysicsEvent(PhysicsEvent.STARTED, {basicPhysics:this}));
if($setangle && angle != null) setAngle(angle);
_sprite.addEventListener(Event.ENTER_FRAME, update, false, 0, true);
+ Debug.output('motion', 40010);
}
/**
@@ -176,6 +179,7 @@ package com.desuade.motion.physics {
_active = false;
_sprite.removeEventListener(Event.ENTER_FRAME, update);
dispatchEvent(new PhysicsEvent(PhysicsEvent.STOPPED, {basicPhysics:this}));
+ Debug.output('motion', 40011);
}
/**
@@ -190,7 +194,7 @@ package com.desuade.motion.physics {
/**
* @private
*/
- protected function update(u:Object):void {
+ public function update(u:Object):void {
velocity += acceleration;
velocity *= _calcfriction;
if(flip) target[property] -= velocity;
@@ -58,6 +58,7 @@ package com.desuade.motion.tweens {
* <li>value:* – the new (end) color. A string or hex is accepted - ie: <code>{value: '#ff0038}</code> or <code>{value:0xff883a}</code></li>
* <li>ease:Function – the easing function to use. Default is Linear.none.</li>
* <li>duration:Number – how long in seconds for the tween to last</li>
+ * <li>hexProperty:String – To tween a hex value instead of a DisplayObject, set this to the property</li>
* </ul>
*
* <p>Example: <code>var mt:BasicColorTween = new BasicColorTween({target:myobj, value:0xff77d5, amount:0.8, duration:2})</code></p>
@@ -83,20 +84,28 @@ package com.desuade.motion.tweens {
* @private
*/
protected override function createTween($to:Object):int {
- _colorholder = $to.target.transform.colorTransform;
+ _colorholder = ($to.hexProperty != undefined) ? ColorHelper.getColorObject('tint', 1, $to.target[$to.hexProperty]) : $to.target.transform.colorTransform;
var cpo:Object = ColorHelper.getColorObject($to.type || 'tint', $to.amount || 1, $to.value, _colorholder);
var pt:PrimitiveMultiTween = BasicTween._tweenholder[PrimitiveTween._count] = new PrimitiveMultiTween(_colorholder, cpo, $to.duration*1000, $to.ease);
pt.addEventListener(TweenEvent.ENDED, endFunc, false, 0, true);
- pt.addEventListener(TweenEvent.UPDATED, colorupdater, false, 0, true);
+ if($to.hexProperty != undefined) pt.addEventListener(TweenEvent.UPDATED, hexcolorupdater, false, 0, true);
+ else pt.addEventListener(TweenEvent.UPDATED, docolorupdater, false, 0, true);
return pt.id;
}
/**
* @private
*/
- protected function colorupdater($o:Object):void {
+ protected function docolorupdater($o:Object):void {
_tweenconfig.target.transform.colorTransform = new ColorTransform(_colorholder.redMultiplier, _colorholder.greenMultiplier, _colorholder.blueMultiplier, _tweenconfig.target.alpha, _colorholder.redOffset, _colorholder.greenOffset, _colorholder.blueOffset);
};
+
+ /**
+ * @private
+ */
+ protected function hexcolorupdater($o:Object):void {
+ _tweenconfig.target[_tweenconfig.hexProperty] = ColorHelper.RGBToHex(_colorholder.redOffset, _colorholder.greenOffset, _colorholder.blueOffset);
+ };
}
@@ -60,6 +60,7 @@ package com.desuade.motion.tweens {
* <li>duration:Number – how long in seconds for the tween to last</li>
* <li>delay:Number – how long in seconds to delay starting the tween</li>
* <li>position:Number – what position to start the tween at 0-1</li>
+ * <li>hexProperty:String – To tween a hex value instead of a DisplayObject, set this to the property</li>
* </ul>
*
* <p>Example: <code>var mt:ColorTween = new ColorTween({target:myobj, value:0xff77d5, amount:0.8, duration:2, ease:Bounce.easeIn, delay:2, position:0})</code></p>
@@ -86,6 +87,7 @@ package com.desuade.motion.tweens {
* @param type the type of color transformation to apply. Defaults to 'tint', see ColorHelper for more types.
* @param amount The amount of transform to apply. Depends on 'type'.
* @param position what position to start the tween at 0-1
+ * @param hexProperty To tween a hex value instead of a DisplayObject, set this to the property
*
* <p>example: ColorTween.tween(myobj, '#ff0055', 2.5, null, 0, 'tint', 1, 0)</p>
*
@@ -96,19 +98,26 @@ package com.desuade.motion.tweens {
* @see com.desuade.utils.ColorHelper#getColorObject()
*
*/
- public static function tween($target:Object, $value:*, $duration:Number, $ease:Function = null, $delay:Number = 0, $type:String = 'tint', $amount:Number = 1, $position:Number = 0):ColorTween {
- var st:ColorTween = new ColorTween({target:$target, value:$value, duration:$duration, ease:$ease, delay:$delay, type:$type, amount:$amount, position:$position});
+ public static function tween($target:Object, $value:*, $duration:Number, $ease:Function = null, $delay:Number = 0, $type:String = 'tint', $amount:Number = 1, $position:Number = 0, $hexProperty:String = null):ColorTween {
+ var st:ColorTween = new ColorTween({target:$target, value:$value, duration:$duration, ease:$ease, delay:$delay, type:$type, amount:$amount, position:$position, hexProperty:$hexProperty});
st.start();
return st;
}
/**
* @private
*/
- protected function colorupdater($o:Object):void {
+ protected function docolorupdater($o:Object):void {
_tweenconfig.target.transform.colorTransform = new ColorTransform(_colorholder.redMultiplier, _colorholder.greenMultiplier, _colorholder.blueMultiplier, _tweenconfig.target.alpha, _colorholder.redOffset, _colorholder.greenOffset, _colorholder.blueOffset);
};
+ /**
+ * @private
+ */
+ protected function hexcolorupdater($o:Object):void {
+ _tweenconfig.target[_tweenconfig.hexProperty] = ColorHelper.RGBToHex(_colorholder.redOffset, _colorholder.greenOffset, _colorholder.blueOffset);
+ };
+
/**
* @private
*/
@@ -120,7 +129,7 @@ package com.desuade.motion.tweens {
return 0;
} else {
var pt:PrimitiveMultiTween;
- _colorholder = $to.target.transform.colorTransform;
+ _colorholder = ($to.hexProperty != undefined && $to.hexProperty != null) ? ColorHelper.getColorObject('tint', 1, $to.target[$to.hexProperty]) : $to.target.transform.colorTransform;
var cpo:Object = ColorHelper.getColorObject($to.type || 'tint', $to.amount || 1, $to.value, _colorholder);
if(_newvals.length == 0){
for (var p:String in cpo) {
@@ -132,7 +141,8 @@ package com.desuade.motion.tweens {
}
pt = BasicTween._tweenholder[PrimitiveTween._count] = new PrimitiveMultiTween(_colorholder, cpo, $to.duration*1000, $to.ease);
pt.addEventListener(TweenEvent.ENDED, endFunc, false, 0, true);
- pt.addEventListener(TweenEvent.UPDATED, colorupdater, false, 0, true);
+ if($to.hexProperty != undefined && $to.hexProperty != null) pt.addEventListener(TweenEvent.UPDATED, hexcolorupdater, false, 0, true);
+ else pt.addEventListener(TweenEvent.UPDATED, docolorupdater, false, 0, true);
if($to.position > 0) {
pt.starttime -= ($to.position*$to.duration)*1000;
if(_newvals.length > 0) {
@@ -117,7 +117,7 @@ package com.desuade.motion.tweens {
* @param position what position to start the tween at 0-1
* @param bezier an array of bezier curve points
*
- * <p>example: Tween.tween(myobj, 'x', 300, 2.5, null, 0, false, 0, [100])</p>
+ * <p>Example: <code>Tween.tween(myobj, 'x', 300, 2.5, null, 0, false, 0, [100])</code></p>
*
* @see PrimitiveTween#target
* @see PrimitiveTween#property

0 comments on commit a5cb13d

Please sign in to comment.