LevelButton behaviour on TDN not working?
by David Janik-Jones · in Torque Game Builder · 01/24/2008 (6:30 am) · 11 replies
I attached the LevelButton behaviour from the TDN behaviours to a graphic in a scene called "Splash" that loads first. Clicking on the graphic is supposed to take you to the only other scene in the project ... "Play." When the LevelButton behaviour is used there is a place in the Edit tab to specify "level to load" which I assume means scene. So I put "Play" as the name of the "level" to load and build the game.
Clicking the graphic takes you to a black screen (not the Play scene which has stuff on screen).
Is there some place in the scripts (i.e., main.cs) that I have to add a reference to the Play scene so that it's recognized as a level? Why isn't the LevelButton script working?
Also, has anyone ever combined the Fade.cs and levelButton.cs to allow you to fade and then pop to a new scene?
Clicking the graphic takes you to a black screen (not the Play scene which has stuff on screen).
Is there some place in the scripts (i.e., main.cs) that I have to add a reference to the Play scene so that it's recognized as a level? Why isn't the LevelButton script working?
Also, has anyone ever combined the Fade.cs and levelButton.cs to allow you to fade and then pop to a new scene?
#2
01/24/2008 (7:02 am)
"Play" is the name of the scene in the project I'm trying to load.
#3
So in order to have a button that loads a new level, you need to use a GuiBitmapButtonCtrl.
01/24/2008 (12:06 pm)
I spent a good chunk of time this past weekend working on a similar problem to yours. After crashing TGB about a million times trying to transition from a title screen "level" to my main game level, I sifted through the forums to try and figure out how to load levels properly and here is what I found:Quote:In general, a function attached to an object in a scenegraph should not directly load a level, in my experience. The problem is that before the new level is loaded, the current level is unloaded, which includes unloading the object currently in the act of loading a new level. You would expect unpredictable results.
So in order to have a button that loads a new level, you need to use a GuiBitmapButtonCtrl.
#4
01/24/2008 (4:09 pm)
Thanks.
#5
01/24/2008 (8:33 pm)
Guys I don't think that's actually the case... Your behavior could always schedule a function that would load the new level into the scenegraph. As long as you use the schedule function properly such as this:schedule( 1000, 0, "loadnewscene", %newscene);and not this way
object.schedule( 1000, "loadnewscene", %newscene);I see no reason why it wouldn't work as expected.
#6
Since everything is being done via behaviors, I've always used %this.schedule. Plain old schedule works though, just tested it. Oh well, guess I can scrap my GUI overlay and go back to sceneObjects - which isn't that bad because I hate working with the GUI editor anyway. Thanks Joe.
01/25/2008 (10:29 am)
....Since everything is being done via behaviors, I've always used %this.schedule. Plain old schedule works though, just tested it. Oh well, guess I can scrap my GUI overlay and go back to sceneObjects - which isn't that bad because I hate working with the GUI editor anyway. Thanks Joe.
#7
01/25/2008 (4:22 pm)
OK, as a newbie programmer how do I make this function in the loadlevel.cs code ...if (!isObject(LevelButtonBehavior))
{
%template = new BehaviorTemplate(LevelButtonBehavior);
%template.friendlyName = "Level Button";
%template.behaviorType = "GUI";
%template.description = "Loads a new level when clicked";
%template.addBehaviorField(hoverImage, "The image to display when mousing over the object", object, "", t2dImageMapDatablock);
%template.addBehaviorField(hoverFrame, "The frame of the hoverImage to display", int, 0);
%template.addBehaviorField(clickImage, "The image to display when clicking on the object", object, "", t2dImageMapDatablock);
%template.addBehaviorField(clickFrame, "The frame of the clickImage to display", int, 0);
%template.addBehaviorField(level, "The level to load on mouse up", string, "");
// ADD SOMETHING HERE ???
}
function LevelButtonBehavior::onBehaviorAdd(%this)
{
%this.owner.setUseMouseEvents(true);
%this.startImage = %this.owner.getImageMap();
%this.startFrame = %this.owner.getFrame();
}
function LevelButtonBehavior::onMouseDown(%this, %modifier, %worldPos)
{
if (!isObject(%this.clickImage))
return;
%this.owner.setImageMap(%this.clickImage, %this.clickFrame);
}
function LevelButtonBehavior::onMouseUp(%this, %modifier, %worldPos)
{
if (isObject(%this.hoverImage))
%this.owner.setImageMap(%this.hoverImage, %this.hoverFrame);
else
%this.owner.setImageMap(%this.startImage, %this.startFrame);
sceneWindow2D.schedule("1","loadLevel",expandFilename( %this.level ) );
// I ASSUME IT GOES HERE ... schedule( 1000, 0, "loadnewscene", %newscene);
}
function LevelButtonBehavior::onMouseEnter(%this, %modifier, %worldPos)
{
if (!isObject(%this.hoverImage))
return;
%this.owner.setImageMap(%this.hoverImage, %this.hoverFrame);
}
function LevelButtonBehavior::onMouseLeave(%this, %modifier, %worldPos)
{
%this.owner.setImageMap(%this.startImage, %this.startFrame);
}
#8
01/25/2008 (6:24 pm)
The "level" value you set for that behavior needs to be a path to a .t2d scene/level file... for example "game/data/levels/playground.t2d".
#9
Thanks Matthew, that was it!
01/25/2008 (8:23 pm)
The full path? Oh, that explains it. I thought it simply needed to be the name. I will try in the morning game/data/levels/Play.t2d. Thanks Matthew, that was it!
#10
if (!isObject(LevelButtonBehavior))
{
%template = new BehaviorTemplate(LevelButtonBehavior);
%template.friendlyName = "Level Button";
%template.behaviorType = "GUI";
%template.description = "Loads a new level when clicked";
%template.addBehaviorField(hoverImage, "The image to display when mousing over the object", object, "", t2dImageMapDatablock);
%template.addBehaviorField(hoverFrame, "The frame of the hoverImage to display", int, 0);
%template.addBehaviorField(clickImage, "The image to display when clicking on the object", object, "", t2dImageMapDatablock);
%template.addBehaviorField(clickFrame, "The frame of the clickImage to display", int, 0);
%template.addBehaviorField(level, "The level to load on mouse up", string, "");
}
function LevelButtonBehavior::onBehaviorAdd(%this)
{
%this.owner.setUseMouseEvents(true);
%this.startImage = %this.owner.getImageMap();
%this.startFrame = %this.owner.getFrame();
}
function LevelButtonBehavior::onMouseDown(%this, %modifier, %worldPos)
{
if (!isObject(%this.clickImage))
return;
%this.owner.setImageMap(%this.clickImage, %this.clickFrame);
}
function LevelButtonBehavior::onMouseUp(%this, %modifier, %worldPos)
{
if (isObject(%this.hoverImage))
%this.owner.setImageMap(%this.hoverImage, %this.hoverFrame);
else
%this.owner.setImageMap(%this.startImage, %this.startFrame);
sceneWindow2D.schedule("1","loadLevel",expandFilename( %this.level ) );
game/data/levels/level1.t2d ;
}
function LevelButtonBehavior::onMouseEnter(%this, %modifier, %worldPos)
{
if (!isObject(%this.hoverImage))
return;
%this.owner.setImageMap(%this.hoverImage, %this.hoverFrame);
}
function LevelButtonBehavior::onMouseLeave(%this, %modifier, %worldPos)
{
%this.owner.setImageMap(%this.startImage, %this.startFrame);
}
03/08/2010 (10:01 am)
I've got the same problem...please help...and also, does the bahaviour have to be assigned toa static sprite or ta a text object?if (!isObject(LevelButtonBehavior))
{
%template = new BehaviorTemplate(LevelButtonBehavior);
%template.friendlyName = "Level Button";
%template.behaviorType = "GUI";
%template.description = "Loads a new level when clicked";
%template.addBehaviorField(hoverImage, "The image to display when mousing over the object", object, "", t2dImageMapDatablock);
%template.addBehaviorField(hoverFrame, "The frame of the hoverImage to display", int, 0);
%template.addBehaviorField(clickImage, "The image to display when clicking on the object", object, "", t2dImageMapDatablock);
%template.addBehaviorField(clickFrame, "The frame of the clickImage to display", int, 0);
%template.addBehaviorField(level, "The level to load on mouse up", string, "");
}
function LevelButtonBehavior::onBehaviorAdd(%this)
{
%this.owner.setUseMouseEvents(true);
%this.startImage = %this.owner.getImageMap();
%this.startFrame = %this.owner.getFrame();
}
function LevelButtonBehavior::onMouseDown(%this, %modifier, %worldPos)
{
if (!isObject(%this.clickImage))
return;
%this.owner.setImageMap(%this.clickImage, %this.clickFrame);
}
function LevelButtonBehavior::onMouseUp(%this, %modifier, %worldPos)
{
if (isObject(%this.hoverImage))
%this.owner.setImageMap(%this.hoverImage, %this.hoverFrame);
else
%this.owner.setImageMap(%this.startImage, %this.startFrame);
sceneWindow2D.schedule("1","loadLevel",expandFilename( %this.level ) );
game/data/levels/level1.t2d ;
}
function LevelButtonBehavior::onMouseEnter(%this, %modifier, %worldPos)
{
if (!isObject(%this.hoverImage))
return;
%this.owner.setImageMap(%this.hoverImage, %this.hoverFrame);
}
function LevelButtonBehavior::onMouseLeave(%this, %modifier, %worldPos)
{
%this.owner.setImageMap(%this.startImage, %this.startFrame);
}
#11
03/09/2010 (12:13 am)
You should not just type a random level name into the "onMouseUp" function. When you attach the behavior to a static sprite (with separate frames for "hover" and "depressed"), you'll put the file name for the level into the "level" field that will appear.
Torque Owner Michael Hartlef