diff --git a/motion/Actuate.hx b/motion/Actuate.hx index 4e8e32e..07e65ed 100644 --- a/motion/Actuate.hx +++ b/motion/Actuate.hx @@ -484,6 +484,29 @@ private class TransformOptions { } + /** + * Creates a new ColorTransform tween + * @param r The r color value + * @param g The g color value + * @param b The b color value + * @param alpha The end alpha of the target. If you wish to tween alpha and tint simultaneously, you must do them both as part of the ColorTransform. A value of null will make no change to the alpha of the object (Default is null) + * @return The current actuator instance, which can be used to apply properties like ease, delay, onComplete or onUpdate + */ + public function multiplyColor (r:Float, g:Float, b:Float, alpha:Null = null):IGenericActuator { + + var properties:Dynamic = { redMultiplier: r, greenMultiplier: g, blueMultiplier: b }; + + if (alpha != null) { + + properties.colorAlpha = alpha; + + } + + return Actuate.tween (target, duration, properties, overwrite, TransformActuator); + + } + + /** * Creates a new SoundTransform tween * @param volume The end volume for the target, or null if you would like to ignore this property (Default is null) @@ -690,4 +713,4 @@ private class ObjectHash { #else typedef ObjectHash = haxe.ds.ObjectMap; -#end \ No newline at end of file +#end diff --git a/motion/actuators/TransformActuator.hx b/motion/actuators/TransformActuator.hx index b2b37d8..93764b8 100644 --- a/motion/actuators/TransformActuator.hx +++ b/motion/actuators/TransformActuator.hx @@ -56,6 +56,12 @@ class TransformActuator extends SimpleActuator { initializeColor (); } + + if (Reflect.hasField (properties, "redMultiplier") && Std.is (target, DisplayObject)) { + + initializeColorMultiply (); + + } if (Reflect.hasField (properties, "soundVolume") || Reflect.hasField (properties, "soundPan")) { @@ -144,6 +150,45 @@ class TransformActuator extends SimpleActuator { } } + + + private function initializeColorMultiply ():Void { + + endColorTransform = new ColorTransform (); + + endColorTransform.redMultiplier = properties.redMultiplier; + endColorTransform.greenMultiplier = properties.greenMultiplier; + endColorTransform.blueMultiplier = properties.blueMultiplier; + + var propertyNames:Array = [ "redMultiplier", "greenMultiplier", "blueMultiplier", "redOffset", "greenOffset", "blueOffset" ]; + + if (Reflect.hasField (properties, "colorAlpha")) { + + endColorTransform.alphaMultiplier = properties.colorAlpha; + propertyNames.push ("alphaMultiplier"); + + } else { + + endColorTransform.alphaMultiplier = getField (target, "alpha"); + + } + + var transform:Transform = getField (target, "transform"); + var begin:ColorTransform = getField (transform, "colorTransform"); + tweenColorTransform = new ColorTransform (); + + var details:PropertyDetails; + var start:Float; + + for (propertyName in propertyNames) { + + start = getField (begin, propertyName); + details = new PropertyDetails (tweenColorTransform, propertyName, start, getField (endColorTransform, propertyName) - start); + propertyDetails.push (details); + + } + + } private function initializeSound ():Void {