Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add multiplyColor transformation #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion motion/Actuate.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Float> = 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)
Expand Down Expand Up @@ -690,4 +713,4 @@ private class ObjectHash <T> {

#else
typedef ObjectHash<T> = haxe.ds.ObjectMap<Dynamic, T>;
#end
#end
45 changes: 45 additions & 0 deletions motion/actuators/TransformActuator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {

Expand Down Expand Up @@ -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 <String> = [ "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 {
Expand Down