Game Development Community

Next level

by Vamperik · in Torque X 2D · 04/09/2008 (3:56 pm) · 19 replies

I am currently having problems with progressing to the next level in my game. Upon completing the level I call this:

public void LevelCompleted()
{
SceneLoader.Load(@"data\levels\level_02.txscene");



}

But nothing happens,
Anyone knows how I can go from one level to another.
Thanks

About the author

Recent Threads

  • Spawn
  • Spawn
  • Jumping character

  • #1
    04/12/2008 (12:06 am)
    Did you called SceneLoader.Unload() first?
    #2
    04/12/2008 (2:37 am)
    I put in:

    public void LevelCompleted()
    {
    SceneLoader.Unload(@"data\levels\level_01.txscene");
    SceneLoader.Load(@"data\levels\level_02.txscene");



    }
    and it now works fine.

    Thanks
    #3
    04/12/2008 (4:44 am)
    Glad I could help :)
    #4
    10/06/2008 (12:43 pm)
    I am having a similar problem. If I call SceneLoader.Unload() and then SceneLoad.Load() the screen goes blank but if I don't call SceneLoader.Unload() then the new scene loads on top of the old scene. However, the new scene is ignored accept for the player. You can controll the player but any collision or anything occurs with the old scene.
    #5
    10/10/2008 (10:09 am)
    I had these same problems and the solution I found was to load a blank scene when the game starts. This scene contains nothing and is never unloaded. Then I load/ unload all level scenes on top of this one.
    I know it is a stupid solution but it worked...
    #6
    11/20/2008 (11:44 am)
    You can also us the true flag which makes the object stay loaded even though you have unloaded that scene it belong to. Note there is a bug in the Torque X that cause the IsPersistent flag not to work when i get home I will post the fix for Pro users.
    #7
    11/20/2008 (12:16 pm)
    Chris C, I ran into that problem with the TorqueX 3D. Basically what I did was moved the definition to a Global.txscene file that I never unload. This ensures that the SceneGraph's Collision Manager remains the entire game. I'm not sure if this is the best way by-design to do this, but it works well for me.

    On a side note, I also store my player and camera objects in the Global.txscene so that they aren't loaded & unloaded every scene. The screen may be going blank because of CameraComponent changes (omission?) from one txscene to the next.

    Hope this helps.
    #8
    11/20/2008 (8:58 pm)
    Here's the code to unload the current scene and load a new scene:

    //Unload the last txscene level file
    Game.Instance.SceneLoader.UnloadLastScene();
    
    
    //Load the txscene level file
    Game.Instance.SceneLoader.Load(@"data\levels\[your scene file name].txscene"); 
    
    
    //create a renderable canvas for the scene   
    GUIStyle stylePlayGui = new GUIStyle();
    GUISceneview playGui = new GUISceneview();
    playGui.Style = stylePlayGui;
    
    
    //switch over to the new canvas   
    GUICanvas.Instance.SetContentControl(playGui);

    The GUISceneview that is created automatically when the engine starts up gets disposed when you unload a scene. The trick is to create a new GUISceneview and push it to the GUICanvas.

    I've been using this code forever. I'd credit the original author if I could remember where I got it. I think maybe I derived it from the Splash Screen tutorial.

    Hope this helps!
    #9
    11/20/2008 (10:35 pm)
    @Josef
    Hey, what namespace does GUIStyle and GUISceneview occupy? I keep getting errors when I try to use it.

    Example: The type or namespace name 'GUIStyle' could not be found (are you missing a using directive or an assembly reference?)
    #10
    11/20/2008 (10:38 pm)
    GarageGames.Torque.GUI

    Here's my complete list of using declarations for the component I use to load scenes:

    using System;
    using System.Collections.Generic;
    using System.Text;
    
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Input;
    
    using Microsoft.Xna.Framework.Audio;
    
    using GarageGames.Torque.Core;
    using GarageGames.Torque.Util;
    using GarageGames.Torque.Sim;
    using GarageGames.Torque.T2D;
    using GarageGames.Torque.GUI;
    using GarageGames.Torque.SceneGraph;
    using GarageGames.Torque.MathUtil;
    
    using GarageGames.Torque.Platform;
    #11
    11/20/2008 (10:46 pm)
    Awesome! Thanks for the speedy reply! Apparently new TX2.0 projects do not include the using GarageGames.Torque.GUI;

    Works like a champ now. :)
    #12
    11/28/2008 (8:03 pm)
    I'm getting an error when I try to load, unload and reload the same level:

    Cannot access a disposed object.
    Object name: 'Texture2D'.

    Does TorqueX delete all the assets with the level as well? Why wouldn't it be able to load it in the same level the second time?
    #13
    11/28/2008 (8:13 pm)
    @Danilo - I haven't seen that since I implemented it in my game. Have you been adding anything manually using just XNA? I just modified the game.cs file right below the main() method to have the following function that takes the scene's name in string format as an argument:

    public void loadNextScene(string nextScene)
            {
                //Unload the last txscene level file
                Game.Instance.SceneLoader.UnloadLastScene();
    
    
                //Load the txscene level file
                Game.Instance.SceneLoader.Load(@nextScene);
    
                
                //create a renderable canvas for the scene   
                GUIStyle stylePlayGui = new GUIStyle();
                GUISceneview playGui = new GUISceneview();
                playGui.Style = stylePlayGui;
    
    
                //switch over to the new canvas   
                GUICanvas.Instance.SetContentControl(playGui);
                 
            }
    #14
    11/28/2008 (9:06 pm)
    I had a problem with a scenario like this that I was able to resolve.

    The problem had to do with object scoping and code I added at the game.cs level that was keeping references to objects in my scene, objects that were going out of scope when the scene was unloaded.

    After a scene was unloaded, if my references to objects in that scene were not also reset or at least set to null, the game would crash with an error about "illegal memory access" if any code tried to make use of those references.

    Also, I was using the scheduling system quite a bit and running into situations where some method call was scheduled but a level unload was happening before the method call had taken place. When the time came for the method to execute it often crashed the game if the method was expecting certain scene objects to exist.

    Ultimately I was able to clean up my logic and implement this in a way that did not cause crashes. I never had a problem with the SceneLoader itself.

    Hope this helps.
    #15
    11/28/2008 (9:31 pm)
    I'm getting an error when I try to load, unload and reload the same level:

    Cannot access a disposed object.
    Object name: 'Texture2D'.

    Does SceneLoader.Unload delete all the assets connections with the level as well? Why wouldn't it be able to load it in the same level the second time?
    #16
    11/28/2008 (9:35 pm)
    Maybe I was not clear earlier. You can absolutely reload a scene after you have unloaded it.

    I do it all the time.
    #17
    11/28/2008 (9:40 pm)
    Hmmm....this seems to work fine with TankBuster sample, but when added to a Platformer Demo I get the 'Texture2D' error?

    Has anyone else tried to make additions to the a Platformer Kit sample utilizing SceneLoader.Unload ?
    #18
    12/03/2008 (11:15 pm)
    No, Josef, you were very clear. There seems to be bug with the Platform Starter Kit.....for some reason, when performing this command with the Platform Starter Kit:

    SceneLoader.UnloadLastScene();

    you'll yield an error, Steve L has the same problem:

    http://www.garagegames.com/mg/forums/result.thread.php?qt=80348

    Is there anyone in tech support that can verify this problem?
    #19
    12/03/2008 (11:36 pm)
    I've owned the platformer starter kit since it was first released but I haven't played with it much.

    Seems like this problem is related to the issue I described earlier.

    You'll have to figure out each game level reference to scene objects and make sure they are properly nulled out or reset when you unload/reload.

    I'm tied up with work for the next couple of weeks. Ping me if you don't have it figured by mid-month and I'll look into it for you.