Beta4 - Some minor bugs with level loading
by Kirakorn Chimkool · in Torque Game Builder · 05/24/2006 (10:28 pm) · 7 replies
I want to load a level and add some scene objects to my existing t2dSceneGraph. So, I've used t2dSceneGraph.loadLevel() to do what I want. However, It didn't work if the level file contain another t2dSceneGraph the scene objects in the level don't added to my existing t2dSceneGraph. It works if you use t2dSceneObjectGroup instead but I think it supposed to work in both ways.
The problem I've found is in the file levelManagement.cs line 87
The function call %sceneGraph.endLevel(); which clear every scene objects in my existing t2dSceneGraph and then call %sceneGraph.addToLevel(%levelFile);
In the function t2dSceneGraph::addToLevel() line 174
The if ((%toSceneGraph.getCount() > 0) && (%fromSceneGraph.getCount() > 0)) statement is never get true and the code block is never reached because the existing t2dSceneGraph is already clear in function loadLevel(). And I think the %toSceneGraph.add(%newGroup); should change to %toSceneGraph.addToScene(%newGroup); instead or the scene objects won't added to scenegraph properly.
I've fixed the problem myself in Beta3 but it still never work I don't know why. The scene objects added to my existing scenegraph properly (I've comment out the endLevel() call and use addToScene as I've mentioned) but the scenegraph didn't update (my scene objects did not showed) unless you click it in the tree browser. Any idea?
Sorry for my english skill, Im trying to improve it anyway ;)
The problem I've found is in the file levelManagement.cs line 87
//---------------------------------------------------------------------------------------------
// t2dSceneGraph.addToLevel
// Loads a level file into a scenegraph.
//---------------------------------------------------------------------------------------------
function t2dSceneGraph::loadLevel(%sceneGraph, %levelFile)
{
%sceneGraph.endLevel();
%newScenegraph = %sceneGraph.addToLevel(%levelFile);The function call %sceneGraph.endLevel(); which clear every scene objects in my existing t2dSceneGraph and then call %sceneGraph.addToLevel(%levelFile);
In the function t2dSceneGraph::addToLevel() line 174
// If the existing scenegraph has objects in it, then the new stuff should probably be
// organized nicely in its own group.
if ((%toSceneGraph.getCount() > 0) && (%fromSceneGraph.getCount() > 0))
{
%newGroup = new t2dSceneObjectGroup();
while (%fromSceneGraph.getCount() > 0)
{
%obj = %fromSceneGraph.getObject(0);
%fromSceneGraph.removeFromScene(%obj);
%obj.setPosition(%obj.getPosition()); // This sets physics.dirty.... =)
%newGroup.add(%obj);
}
%toSceneGraph.add(%newGroup);
}The if ((%toSceneGraph.getCount() > 0) && (%fromSceneGraph.getCount() > 0)) statement is never get true and the code block is never reached because the existing t2dSceneGraph is already clear in function loadLevel(). And I think the %toSceneGraph.add(%newGroup); should change to %toSceneGraph.addToScene(%newGroup); instead or the scene objects won't added to scenegraph properly.
I've fixed the problem myself in Beta3 but it still never work I don't know why. The scene objects added to my existing scenegraph properly (I've comment out the endLevel() call and use addToScene as I've mentioned) but the scenegraph didn't update (my scene objects did not showed) unless you click it in the tree browser. Any idea?
Sorry for my english skill, Im trying to improve it anyway ;)
#2
If I misunderstood something, please explain it more.
Thanks :)
05/29/2006 (5:30 am)
Yes, for now I've created my own loadLevel() and use t2dSceneGraph::addToLevel() directly. But my point is if the level file contain t2dSceneGraph like the code below, the scene objects won't be added to my existing scene graph because the "if ((%toSceneGraph.getCount() > 0) && (%fromSceneGraph.getCount() > 0))" never return true.%levelContent = new t2dSceneGraph() {
canSaveDynamicFields = "1";
cameraSize = "800 600";
cameraPosition = "0 0";If I misunderstood something, please explain it more.
Thanks :)
#3
So if you want to add something to the level - just call t2dSceneGraph::addToLevel(). You do not need t2dSceneGraph::loadLevel() then.
If you want to add one level to another within the level builder then use File -> Import...
Let me know if that helped :)
05/29/2006 (6:26 am)
I think t2dSceneGraph::loadLevel() is just supposed to always clear the scenegraph before loading the new content. And t2dSceneGraph::addToLevel() should do what its name says: add something to a level.So if you want to add something to the level - just call t2dSceneGraph::addToLevel(). You do not need t2dSceneGraph::loadLevel() then.
If you want to add one level to another within the level builder then use File -> Import...
Let me know if that helped :)
#4
This is lead me to belive that, the t2dSceneGraph::loadLevel() is desired to support a level file contain a scenegraph. However, the t2dSceneGraph::loadLevel() will never work that way because of the combination of %sceneGraph.endLevel(); and if ((%toSceneGraph.getCount() > 0) && (%fromSceneGraph.getCount() > 0)) as I've mentioned above.
You can try this yourself by creating a scenegraph in you script then create a simple level file contain some sprites in LevelBuilder. When you use t2dSceneGraph::loadLevel() you will see my problem.
For now, my simple level file work perfectly by using t2dSceneObjectGroup and I'm happy with it. Thank you for the "File->Import" tip, I don't know that. It's very helpful for my future project :)
05/29/2006 (8:22 pm)
I totally agree with you for the behavior of loadLevel() and addToLevel(). It's make perfect sense. I'm thinking the same way as you. My only problem is, Is t2dSceneGraph::loadLevel() support a level file that contain t2dSceneGraph or not? If it only support a level file that contain t2dSceneObjectGroup or single scene object then it's OK. But in the TGBReference document it says:Quote:
Notes
The level file can contain a scenegraph, a group of scene objects, or a single scene object.
This is lead me to belive that, the t2dSceneGraph::loadLevel() is desired to support a level file contain a scenegraph. However, the t2dSceneGraph::loadLevel() will never work that way because of the combination of %sceneGraph.endLevel(); and if ((%toSceneGraph.getCount() > 0) && (%fromSceneGraph.getCount() > 0)) as I've mentioned above.
You can try this yourself by creating a scenegraph in you script then create a simple level file contain some sprites in LevelBuilder. When you use t2dSceneGraph::loadLevel() you will see my problem.
For now, my simple level file work perfectly by using t2dSceneObjectGroup and I'm happy with it. Thank you for the "File->Import" tip, I don't know that. It's very helpful for my future project :)
#5
Sorry for not understanding what you meant :)
05/30/2006 (1:12 am)
Ah, ok, I think I get what you mean. If the sceneGraph you want to load your level into is empty then nothing will be loaded. Is it that?Sorry for not understanding what you meant :)
#6
May be, It's my fault to didn't post a complete code (and my english skill as well) that made you misunderstood. I very appreciate your kind help and response on this forum, so don't worried :)
05/30/2006 (1:45 am)
Yes, that's what I mean (in case you are using addLevel). But actually the scenegraph will always empty because of %sceneGraph.endLevel(); is always called if you are using t2dSceneGraph::loadLevel().May be, It's my fault to didn't post a complete code (and my english skill as well) that made you misunderstood. I very appreciate your kind help and response on this forum, so don't worried :)
#7
Thank you for posting and getting me to understand this bug. I'll probably fix it later this day and then it should be resolved in the next release.
05/30/2006 (8:28 am)
No problem :)Thank you for posting and getting me to understand this bug. I'll probably fix it later this day and then it should be resolved in the next release.
Torque Owner Michael Woerister