Last active
August 29, 2015 14:02
-
-
Save KraigWalker/e7d9a23e3df79a2f1d0d to your computer and use it in GitHub Desktop.
Famo.us - Fade in a Renderable's Opacity with a Quick Utility Function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Utility function that allows for the quick creation of a StateModifier to modifiy the opacity of a renderable | |
* | |
* @param {!number} startOpacity The initial opacity of the object at the start of the transition (0-1) | |
* @param {!number} endOpacity The final opacity of the object at the end of the transition (0-1) | |
* @param {Transition} transition The curve function and duration that affects the opacity | |
* @param {function} callback Callback function after the transition | |
* @return {StateModifier} | |
* | |
* @example | |
* // Fades in an object from 0 to full opacity using the inSine transition from Easing.js | |
* // Logs "Fade Complete!" when done. | |
* mainContext.add(fadeOpacity(0, 1, 'inSine', function(){ console.log('Fade Complete!'); } ) | |
* .add(mySurface); | |
*/ | |
function fadeOpacity(startOpacity, endOpacity, transition, callback) { | |
var stateModifier = new StateModifier(); | |
stateModifier.setOpacity(startOpacity); | |
stateModifier.setOpacity(endOpacity, transition, callback); | |
return stateModifier; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment