public void LoadScene(Scene scene, bool applyTransition, bool disposeCurrentScene) { var nextWaitingScene = new NextWaitingScene(scene, applyTransition, disposeCurrentScene); if (_isTransitionRuning) { _waitingScenes[scene.GetType()] = nextWaitingScene; } if (applyTransition) { if (_isTransitionRuning) { return; } _elapsedTime = 0f; _progress = 0f; _nextScene = nextWaitingScene; _isTransitionRuning = true; } else { if (!_isTransitionRuning) { SetScene(scene, disposeCurrentScene); } } }
public void Update(GameTime gameTime) { if (_nextScene != null && _isTransitionRuning) { _elapsedTime += gameTime.ElapsedGameTime.Milliseconds / 1000f; var nextScene = _nextScene.Scene; _progress = Math.Min(1f, _elapsedTime); nextScene.Update(gameTime); if (_progress == 1f) { SetScene(nextScene, _nextScene.DisposeCurrentScene); _nextScene = null; _isTransitionRuning = false; if (_waitingScenes.Count > 0) { var scene = _waitingScenes.ElementAt(0); _waitingScenes.Remove(scene.Key); LoadScene(scene.Value.Scene, scene.Value.ApplyTransition, scene.Value.DisposeCurrentScene); } else { _progress = 0f; } } } else { CurrentScene.Update(gameTime); } }