how can I load a New Level?
by Jacob Caraballo · in Torque Game Builder · 03/01/2011 (10:25 pm) · 2 replies
I've been trying to figure this out, but I can't.
How can I change a level when I collide with a certain object - for example, I unlock a door and when i go through the door, a new level loads.
I made the behavior below, but it's not working correctly.. It is loading the level, but it's loading it when right when the game starts. I want the level to load onCollision with the object.
if (!isObject(LevelChangerBehavior))
{
%template = new BehaviorTemplate(LevelChangerBehavior);
%template.friendlyName = "Change Level on Collision";
%template.behaviorType = "Game";
%template.description = "Changes to Level on Collision.";
%template.addBehaviorField(level, "Level to change (.t2d)", string, "");
}
function LevelChangerBehavior::onBehaviorAdd(%this)
{
%this.owner.collisionCallback = true;
}
function LevelChangerBehavior::onCollision(%this, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)
{
%this.changeLevel();
}
function LevelChangerBehavior::changeLevel(%this)
{
sceneWindow2D.schedule(1,"loadLevel", "game/data/levels/" @ %this.level @ ".t2d");
}
thanks very much and God bless!
How can I change a level when I collide with a certain object - for example, I unlock a door and when i go through the door, a new level loads.
I made the behavior below, but it's not working correctly.. It is loading the level, but it's loading it when right when the game starts. I want the level to load onCollision with the object.
if (!isObject(LevelChangerBehavior))
{
%template = new BehaviorTemplate(LevelChangerBehavior);
%template.friendlyName = "Change Level on Collision";
%template.behaviorType = "Game";
%template.description = "Changes to Level on Collision.";
%template.addBehaviorField(level, "Level to change (.t2d)", string, "");
}
function LevelChangerBehavior::onBehaviorAdd(%this)
{
%this.owner.collisionCallback = true;
}
function LevelChangerBehavior::onCollision(%this, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)
{
%this.changeLevel();
}
function LevelChangerBehavior::changeLevel(%this)
{
sceneWindow2D.schedule(1,"loadLevel", "game/data/levels/" @ %this.level @ ".t2d");
}
thanks very much and God bless!
#2
The changeLevel() method is also unnecessary. You might as well use a globally available function.
03/02/2011 (5:33 am)
Check who you're colliding with in the onCollision() method too (%dstObj). I'm not sure throwing a rock through a door to load new levels is desirable ;)The changeLevel() method is also unnecessary. You might as well use a globally available function.
Jacob Caraballo
The behavior above works fine.... Sorry :)