Platformer Kit level load bug?
by Danilo Buendia · in Torque X Platformer Kit · 12/08/2008 (11:13 am) · 13 replies
The Platformer Kit doesn't seem to function with the level load/unload commands. Has anyone been able successfully load and unload levels with the Platformer Kit code?
Here is my problem:
SceneLoader.Load(@\"data\\levels\\level_01.txscene\");
--works fine at first, but when I go to unload the current scene:
SceneLoader.UnloadLastScene();
--and reload with the SceneLoader line before, I get this:
This error occurs in Main.cs:
game.Run(); <----------------------------- Cannot access a disposed object. Object name: \'Texture2D\'.
I am trying to change levels when the GoldenEggCollectibleComponent is collected, but I keep hitting this error.
IS the Platformer Kit designed to be compatible with the level load/unload functions?
Here is my problem:
SceneLoader.Load(@\"data\\levels\\level_01.txscene\");
--works fine at first, but when I go to unload the current scene:
SceneLoader.UnloadLastScene();
--and reload with the SceneLoader line before, I get this:
This error occurs in Main.cs:
game.Run(); <----------------------------- Cannot access a disposed object. Object name: \'Texture2D\'.
I am trying to change levels when the GoldenEggCollectibleComponent is collected, but I keep hitting this error.
IS the Platformer Kit designed to be compatible with the level load/unload functions?
#3
12/17/2008 (12:34 pm)
THANK YOU FOR THE RESPONSE! I was starting to loose hope....
#4
12/17/2008 (1:11 pm)
Don't get your hopes up mate. No one has managed to do it yet!
#5
NO ONE has been able to load more than 1 level utilizing the Platform Starter Kit?!
There goes the hope...
12/17/2008 (1:23 pm)
?!?!?!NO ONE has been able to load more than 1 level utilizing the Platform Starter Kit?!
There goes the hope...
#6
This is caused by references to the FontSprite...if you resolve this, you should be able to load and unload levels without problems.
02/08/2009 (1:13 am)
This is not a bug per se...This is caused by references to the FontSprite...if you resolve this, you should be able to load and unload levels without problems.
#7
02/09/2009 (3:11 am)
Danilo, could you give more detail?
#8
02/09/2009 (10:15 pm)
At second look, it doesn't matter, because porting the Platformer Kit to XNA 3.0 breaks it again. Sorry guys. I'll message again if I find a fix.
#9
_fontBatch is a reference to the SpriteBatch of XNA.
I have tried to fire methods to try and have the XNA implementation clean up before the next scene is loaded but with no luck.
I am now trying to call the Reset method of the FontRender prior to loading the next scene.
I will post out what my results where.
02/11/2009 (9:20 am)
From what I can determine the object disposed message is in the FontRender class when it tries to do _fontBatch.End()._fontBatch is a reference to the SpriteBatch of XNA.
I have tried to fire methods to try and have the XNA implementation clean up before the next scene is loaded but with no luck.
I am now trying to call the Reset method of the FontRender prior to loading the next scene.
I will post out what my results where.
#10
I'm converting to XNA 3.0 now...I'll post more on this issue later.
02/11/2009 (11:21 am)
Yes, Victor is on the right path. If you just comment out all references to the sprite fonted UI elements, it will run AND you'll be able to load and unload levels.I'm converting to XNA 3.0 now...I'll post more on this issue later.
#11
Created a new Platform Starter Game and updated the references to Torque and PlatformFramework.
Copied the sample_level.txtscene to sample_level1.txtscene and sample_level2.txtscene. Moved the dragon to different positions on each scene.
Added a bindcommand to the playercontroller to call a load level method and in that method switched between the three scenes.
Ran the game and was able to press the key and load each level with no problem. Note: these levels have no sound and no GUI on them. They are static scenes with no camera movement.
Here is the LoadLevel method I created:
public void LoadLevel()
{
string levelName = null;
string levelMask = @"data\levels\sample_level{0}.txscene";
++_levelNumber;
if (_levelNumber > 2)
{
_levelNumber = 0;
levelName = string.Format(levelMask, "");
}
else
{
levelName = string.Format(levelMask, _levelNumber);
}
Game.Instance.SceneLoader.UnloadLastScene();
Game.Instance.SceneLoader.Load(levelName);
// create game gui
GUIStyle playStyle = new GUIStyle();
GUISceneview play = new GUISceneview();
play.Name = "PlayScreen";
play.Style = playStyle;
T2DSceneCamera camera = TorqueObjectDatabase.Instance.FindObject<T2DSceneCamera>("Camera");
play.Camera = camera;
GUICanvas.Instance.SetContentControl(play);
}
I did it quick and dirty for example only.
02/14/2009 (6:23 am)
OK, updated Torque and PlateformFramework to XNA 3.0.Created a new Platform Starter Game and updated the references to Torque and PlatformFramework.
Copied the sample_level.txtscene to sample_level1.txtscene and sample_level2.txtscene. Moved the dragon to different positions on each scene.
Added a bindcommand to the playercontroller to call a load level method and in that method switched between the three scenes.
Ran the game and was able to press the key and load each level with no problem. Note: these levels have no sound and no GUI on them. They are static scenes with no camera movement.
Here is the LoadLevel method I created:
public void LoadLevel()
{
string levelName = null;
string levelMask = @"data\levels\sample_level{0}.txscene";
++_levelNumber;
if (_levelNumber > 2)
{
_levelNumber = 0;
levelName = string.Format(levelMask, "");
}
else
{
levelName = string.Format(levelMask, _levelNumber);
}
Game.Instance.SceneLoader.UnloadLastScene();
Game.Instance.SceneLoader.Load(levelName);
// create game gui
GUIStyle playStyle = new GUIStyle();
GUISceneview play = new GUISceneview();
play.Name = "PlayScreen";
play.Style = playStyle;
T2DSceneCamera camera = TorqueObjectDatabase.Instance.FindObject<T2DSceneCamera>("Camera");
play.Camera = camera;
GUICanvas.Instance.SetContentControl(play);
}
I did it quick and dirty for example only.
#12
I added a more complex scene with some of the components from the platformer demo. There is a water tile map, a dirt platform tile map and a ActorPuppet with a PlayerDragonActor. I set the parallaxmanagers camera. This simple scene is not scene 4.
In toggling through the scenes when I came to the forth scene the system threw a null reference exception. I traced it down to where it was trying to calc the distance for a sound event.
This all happend in the ActorComponent class. I went ahead an added the following to the _OnRegister event for that class.
// reset the camera if null (Add this above the _initAnimationManager)
if (this.SceneObject.SceneGraph.Camera == null)
{
this.SceneObject.SceneGraph.Camera = TorqueObjectDatabase.Instance.FindObject<T2DSceneCamera>("Camera");
}
// initialize animation manager
// (this will handle all our animations and transitions)
_initAnimationManager();
Still adding in features and processing the unload and loads. Will keep you posted.
02/14/2009 (8:52 am)
Update:I added a more complex scene with some of the components from the platformer demo. There is a water tile map, a dirt platform tile map and a ActorPuppet with a PlayerDragonActor. I set the parallaxmanagers camera. This simple scene is not scene 4.
In toggling through the scenes when I came to the forth scene the system threw a null reference exception. I traced it down to where it was trying to calc the distance for a sound event.
This all happend in the ActorComponent class. I went ahead an added the following to the _OnRegister event for that class.
// reset the camera if null (Add this above the _initAnimationManager)
if (this.SceneObject.SceneGraph.Camera == null)
{
this.SceneObject.SceneGraph.Camera = TorqueObjectDatabase.Instance.FindObject<T2DSceneCamera>("Camera");
}
// initialize animation manager
// (this will handle all our animations and transitions)
_initAnimationManager();
Still adding in features and processing the unload and loads. Will keep you posted.
#13
" game.Run(); <----------------------------- Cannot access a disposed object. Object name: \'Texture2D\'. "
thanks
01/30/2010 (3:25 am)
can someone spell this out in terms that a newbie can understand.. Im having the same error.. Step by step how and what do I do to fix this.. " game.Run(); <----------------------------- Cannot access a disposed object. Object name: \'Texture2D\'. "
thanks
Torque Owner Danilo Buendia
Default Studio Name
So the Platformer Kit is intended to help you ship a 1 level game? That doesn't seem correct.