Game Development Community

Going onto a new level

by Solloman · in Torque X 2D · 04/18/2011 (12:34 pm) · 11 replies

Ok, im trying to just finish this game, i dont care anymore lol

But lets say my player collides with an object, on which that object kills and disappears,
granting the player to proceed onto the next level (next torque scene)

How the f**k does this work, because its driving me insane!!!


#1
04/18/2011 (2:02 pm)
You can use SceneLoader.UnloadLastScene() and SceneLoader.Load() to unload and load a scene

Game.Instance.SceneLoader.UnloadLastScene();
Game.Instance.SceneLoader.Load(@"data\levels\Level2.txscene");
#2
04/18/2011 (2:37 pm)
@Aaron Thanks for the reply, how and where would this go in the game.cs file? and how does it incorporate in the Torque X Builder, my programming skills aint brill tbh
#3
04/18/2011 (2:53 pm)
I just want the player to collide with an object, then the next scene will load up
#4
04/19/2011 (1:24 pm)
@Solloman: I try to keep my game.cs real basic, keeping most game code in additional .cs files.

1) Setup a delegates file if you dont already have one (I call mine myDelegates.cs). If your creating a new file just copy and paste the following code.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using GarageGames.Torque.Core;
using GarageGames.Torque.Util;
using GarageGames.Torque.Sim;
using GarageGames.Torque.T2D;
using GarageGames.Torque.SceneGraph;
using GarageGames.Torque.MathUtil;

namespace StarterGame2D
{
    [TorqueXmlSchemaType]
    public class myDelegates
    {

        [TorqueXmlSchemaType]
        public static T2DOnCollisionDelegate NextLevel
        {
            get { return LoadLevel; }
        }

        public static void LoadLevel(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info, ref T2DResolveCollisionDelegate resolve, ref T2DCollisionMaterial physicsMaterial)
        {
            Game.Instance.SceneLoader.UnloadLastScene();
            Game.Instance.SceneLoader.Load(@"data\levels\Level2.txscene");  
        }
    }
}

Explained: NextLevel will now be exposed to the TX2D Editor as a OnCollision option. When the collision is detected, it will load LoadLevel

2) Once you build the new file TX2D will prompt you to reload, once this happens you can now set your player to collide with the object and set the OnCollision to NextLevel
#5
04/20/2011 (2:12 am)
@Aaron Thanks man, this really helped...

Only prob is every time my player collides with the chosen object, it just turns to a black screen, is there anything i should be aware of, i mean i have made sure that there is an image of some kind in the next scene to detect?
#6
04/21/2011 (5:39 pm)
@Solloman: Does your camera follow the player on the previous level? Sounds like your camera needs to be relocated.
#7
04/24/2011 (1:40 pm)
Sorry I have been absent from these forums. Try this code:
static public void setToSceneGraph()
        {
            T2DSceneGraph graph = new T2DSceneGraph(); ;
            foreach (T2DSceneCamera _cam in TorqueObjectDatabase.Instance.FindObjects<T2DSceneCamera>())
            {
                T2DSceneCamera temp = _cam;
                if (_cam.SceneGraph.Folder != null)
                {
                    graph = _cam.SceneGraph as T2DSceneGraph;
                    break;
                }
            }
            foreach (ISceneObject2D obj in TorqueObjectDatabase.Instance.FindObjects<ISceneObject2D>())
            {
                obj.SceneGraph = graph;
            }
            foreach (T2DSceneGraph _graph in TorqueObjectDatabase.Instance.FindObjects<T2DSceneGraph>())
            {
                if (_graph != graph)
                    _graph.MarkForDelete = true;
            }
        }

After every load and unload of a scene. I have been doing it across all my games, since 3.1. Including Moonbreaker, and my other unreleased games. It basically insures all your stuff in synced to the right scene graphs and cameras. Until the source does this automatically, I found this is the only way to do the scene loading i like to do.
#8
04/25/2011 (1:35 pm)
i placed the code just after aarons code:

Game.Instance.SceneLoader.UnloadLastScene();
Game.Instance.SceneLoader.Load(@"data\levels\Level2.txscene");
}

with a few tweaks, i debugged it and it still plays black...
i Will copy and paste the code on here after this thread,
just to make sure if you can spot the error?
#9
04/25/2011 (1:38 pm)
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using GarageGames.Torque.Core;
using GarageGames.Torque.Util;
using GarageGames.Torque.Sim;
using GarageGames.Torque.T2D;
using GarageGames.Torque.SceneGraph;
using GarageGames.Torque.MathUtil;

namespace StarterGame2D
{
[TorqueXmlSchemaType]
public class myDelegates
{

[TorqueXmlSchemaType]
public static T2DOnCollisionDelegate NextLevel
{
get { return LoadLevel; }
}

public static void LoadLevel(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info, ref T2DResolveCollisionDelegate resolve, ref T2DCollisionMaterial physicsMaterial)
{
Game.Instance.SceneLoader.UnloadLastScene();
Game.Instance.SceneLoader.Load(@"data\levels\level2.txscene");
}

static public void setToSceneGraph()
{
T2DSceneGraph graph = new T2DSceneGraph(); ;
foreach (T2DSceneCamera _cam in TorqueObjectDatabase.Instance.FindObjects<T2DSceneCamera>())
{
T2DSceneCamera temp = _cam;
if (_cam.SceneGraph.Folder != null)
{
graph = _cam.SceneGraph as T2DSceneGraph;
break;
}
}
foreach (ISceneObject2D obj in TorqueObjectDatabase.Instance.FindObjects<ISceneObject2D>())
{
obj.SceneGraph = graph;
}
foreach (T2DSceneGraph _graph in TorqueObjectDatabase.Instance.FindObjects<T2DSceneGraph>())
{
if (_graph != graph)
_graph.MarkForDelete = true;
}
}
}
}
#10
04/27/2011 (9:19 pm)
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using GarageGames.Torque.Core;
using GarageGames.Torque.Util;
using GarageGames.Torque.Sim;
using GarageGames.Torque.T2D;
using GarageGames.Torque.SceneGraph;
using GarageGames.Torque.MathUtil;

namespace StarterGame2D
{
[TorqueXmlSchemaType]
public class myDelegates
{

[TorqueXmlSchemaType]
public static T2DOnCollisionDelegate NextLevel
{
get { return LoadLevel; }
}

public static void LoadLevel(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info, ref T2DResolveCollisionDelegate resolve, ref T2DCollisionMaterial physicsMaterial)
{
Game.Instance.SceneLoader.UnloadLastScene();
Game.Instance.SceneLoader.Load(@"datalevelslevel2.txscene");
//add this line of code here to call the function perhaps.
setToSceneGraph();
}

static public void setToSceneGraph() 
{ 
T2DSceneGraph graph = new T2DSceneGraph(); ; 
foreach (T2DSceneCamera _cam in TorqueObjectDatabase.Instance.FindObjects<T2DSceneCamera>()) 
{ 
T2DSceneCamera temp = _cam; 
//place breakerpoint here to see if you are finding a camera.
if (_cam.SceneGraph.Folder != null) 
{ 
//place breakerpoint here, make sure you are finding a scene graph.
graph = _cam.SceneGraph as T2DSceneGraph; 
break; 
} 
} 
foreach (ISceneObject2D obj in TorqueObjectDatabase.Instance.FindObjects<ISceneObject2D>()) 
{ 
obj.SceneGraph = graph; 
} 
foreach (T2DSceneGraph _graph in TorqueObjectDatabase.Instance.FindObjects<T2DSceneGraph>()) 
{ 
//place breakerpoint here, for kicks, and see if you are getting rid of any excess scene graphs (i find this is just good practice, to see what is going on)
if (_graph != graph) 
_graph.MarkForDelete = true; 
} 
} 
}
}

once you have placed that code, and followed those break points, let me know if you are still having issues.

I myself will go through and run some of this code, and see if I can spot what the differences are. But in general, the more loading, unloading, and complicated things you are doing, the more specific your design pattern is going to need to be. At some point you will have to know what a Scene View is, and what a Camera is and What a scene graph is, to use the engine to it's full potential.
#11
05/13/2011 (11:18 am)
I copied and pasted the code, yet still the same ""BLACKNESS""
altough what do u mean by breakpoints, tried searching on wiki and it means some type of pause system... This is doing my head in, agian did u see anything in the code?