/// <summary> /// Load a scene. If the scene is already loaded, the existing instance is returned. /// </summary> /// <param name="sceneFileName"></param> /// <returns></returns> public TorqueSceneData Load(string sceneFileName) { // already loaded? TorqueSceneData scene; if (_loadedScenes.TryGetValue(sceneFileName, out scene)) { _lastLoadedScene = scene; return scene; } // no, create new scene scene = new TorqueSceneData(); scene.PreloadMaterials = true; scene.Deserializer = Deserializer; // we'll intercept content load exceptions, so that we display a (hopefully) helpful message for dealing with them try { // deserialize scene.Load(sceneFileName); } catch (ContentLoadException e) { string msg = "SceneLoader.Load - Error loading XML file: \'" + sceneFileName + "\', ContentLoadException: \'" + e.Message + "\' If you are using TXB, make sure that you have saved your project, then rebuild your game in Express."; Assert.Fatal(false, msg); #if !XBOX if (_exitOnFailedLoad) System.Environment.Exit(GameExitCodes.SceneLoaderError); // this is here so that TXB knows we failed due to a content load problem #endif throw e; // in case we did not exit } // add scene to loaded list _loadedScenes.Add(sceneFileName, scene); _lastLoadedScene = scene; // call delegate if (_onSceneLoaded != null) _onSceneLoaded(sceneFileName, scene); return scene; }
/// <summary> /// Unload the specified scene object. It is an error if the scene null or not loaded. /// </summary> /// <param name="scene">The scene object to unload.</param> public void Unload(TorqueSceneData scene) { Assert.Fatal(scene != null, "SceneLoader.Unload - Attempting to unload null scene."); Assert.Fatal(scene.Loaded, "SceneLoader.Unload - Specified scene not actually loaded"); // unload scene.Unload(); // remove from loaded scenes string keyToRemove = string.Empty; if (_loadedScenes.ContainsValue(scene)) { foreach (string key in _loadedScenes.Keys) { if (_loadedScenes[key] == scene) { keyToRemove = key; break; } } if (keyToRemove != string.Empty) _loadedScenes.Remove(keyToRemove); } if (_lastLoadedScene == scene) _lastLoadedScene = null; // call delegate if (_onSceneUnloaded != null) _onSceneUnloaded(keyToRemove, scene); }
public void SetCurrentScene(TorqueSceneData currentScene) { this.currentScene = currentScene; }
public void Reset() { SceneLoader.UnloadLastScene(); if (paused) TogglePause(); currentScene = SceneLoader.Load(@"data\levels\Level1.txscene");//SceneLoader.Load(@"data\levels\Level1.txscene"); }
private bool LoadLevel(out string error, string[] parameters) { error = null; if (parameters != null) { string scene = parameters[0]; currentScene.OnUnloaded = delegate() { foreach (object obj in currentScene.Objects) { T2DSceneObject txObj = null; try { txObj = (T2DSceneObject)obj; } catch (Exception e) { TorqueConsole.Error("SceneObject cast failed"); } if (txObj != null) txObj.Visible = false; } }; currentScene.Unload(); currentScene = SceneLoader.Load(@"data\levels\" + scene + ".txscene"); //SceneLoader.UnloadLastScene(); return true; } else error = "No level specified. Please specify a level to load."; return false; }
/// <summary> /// Load the named level and return a new TorqueSceneData instance. In order to customize the Level data load process you must /// create the TorqueSceneData object yourself and call Load on it. /// </summary> /// <param name="filename">The filename to load</param> /// <param name="extraAssemblies">List of assemblies to add to the deserializer's assembly list, for finding new types. Usually can be null.</param> /// <returns>A TorqueSceneData instance</returns> public static TorqueSceneData LoadScene(string filename, List<Assembly> extraAssemblies) { TorqueSceneData ld = new TorqueSceneData(); return ld.Load(filename, extraAssemblies); }
public override void OnRender(Vector2 offset, RectangleF updateRect) { if (fadeColour.A > 150) { fadeColour.A -= 1; Style.FillColor[CustomColor.ColorBase] = fadeColour; } else { currentScene = Game.Instance.SceneLoader.Load(@"data\levels\Level1.txscene"); Game.Instance.SetCurrentScene(currentScene); GUICanvas.Instance.PopDialogControl(this); SoundManager.Instance.StopAllCues(); SoundManager.Instance.PlaySound("music", "level 1"); } base.OnRender(offset, updateRect); }