private void opacityUp() { opacity += 0.05f; opacityColor = new Microsoft.Xna.Framework.Color(opacity, opacity, opacity); if (opacity >= 1) // done { GameLogicTick -= fadeHandle; fadeHandle = null; if (fadeFinished != null) { fadeFinished(); } fadeFinished = null; } }
private void opacityDown(Action callback) { opacity -= 0.05f; opacityColor = new Microsoft.Xna.Framework.Color(opacity, opacity, opacity); if (opacity <= 0) { // call the callback, then switch to fading in if (callback != null) { callback(); } GameLogicTick -= fadeHandle; fadeHandle = new GameTickEventHandler(e => opacityUp()); GameLogicTick += fadeHandle; } }
/// <summary> /// Fades the screen to black, calls an optional callback function, and then fades back in, /// and calls another callback function when done. /// </summary> /// <param name="callback">The function to call when the screen is black. Can be null.</param> /// <param name="finished">The function to call when the transition is finished. Can be null.</param> public void FadeTransition(Action callback, Action finished = null) { // if a fade in is in progress, finish that and immediately // switch to the new fade out if (fadeHandle != null) { GameLogicTick -= fadeHandle; if (fadeFinished != null) { fadeFinished(); } } fadeHandle = new GameTickEventHandler(e => opacityDown(callback)); GameLogicTick += fadeHandle; fadeFinished = finished; }
/// <summary> /// Calls a function after a given number of frames. /// </summary> /// <param name="callback">The callback function to call.</param> /// <param name="progress">A function called each frame to report the progress of the delay.</param> /// <param name="delay">The number of frames to wait before calling.</param> public void DelayedCall(Action callback, Action <int> progress, int delay) { int count = 0; GameTickEventHandler handler = e => { count++; if (progress != null) { progress(count); } }; handler += e => { if (delay == count) { if (callback != null) { callback(); } GameLogicTick -= handler; } }; GameLogicTick += handler; }
private void opacityUp() { opacity += 0.05f; opacityColor = new Microsoft.Xna.Framework.Color(opacity, opacity, opacity); if (opacity >= 1) // done { GameLogicTick -= fadeHandle; fadeHandle = null; if (fadeFinished != null) fadeFinished(); fadeFinished = null; } }
private void opacityDown(Action callback) { opacity -= 0.05f; opacityColor = new Microsoft.Xna.Framework.Color(opacity, opacity, opacity); if (opacity <= 0) { // call the callback, then switch to fading in if (callback != null) callback(); GameLogicTick -= fadeHandle; fadeHandle = new GameTickEventHandler(e => opacityUp()); GameLogicTick += fadeHandle; } }
/// <summary> /// Fades the screen to black, calls an optional callback function, and then fades back in, /// and calls another callback function when done. /// </summary> /// <param name="callback">The function to call when the screen is black. Can be null.</param> /// <param name="finished">The function to call when the transition is finished. Can be null.</param> public void FadeTransition(Action callback, Action finished = null) { // if a fade in is in progress, finish that and immediately // switch to the new fade out if (fadeHandle != null) { GameLogicTick -= fadeHandle; if (fadeFinished != null) { fadeFinished(); } } fadeHandle = new GameTickEventHandler(e => opacityDown(callback)); GameLogicTick += fadeHandle; fadeFinished = finished; }