Game Development Community

The Infamous Scene Loading/Menu System/Camera Bug! All TX2D community members needed!

by Tim Newsome-Ward · in Torque X Platformer Kit · 09/03/2010 (12:38 pm) · 5 replies

This seems to be a plague among the TX2D and the TXPSK forums. The changing of scenes!

I’ve recently purchased the Platform Starter Kit and began dissecting it. I wanted to add aframework in first, such as a functioning menu system and level changing functionality as this added in later can cause huge problems!

I have managed to get a menu working based on Henry's Game kit code, Dro Sarhadian's splash screen tutorial and the PSK demo. Well at least to the point where the scene is loaded.

Initially I received this error in the DrillActorComponent.cs file:

System.NullReferenceException was unhandled
return Vector2.Distance(_actor.Position, (SceneObject.SceneGraph.Camera as T2DSceneCamera).Position);

So I began dissecting further, I used the exited demo_modified scene file and removed everything bar the character, the tile maps and the sky. I also a entered a camera name in the camera rollout box in the editor.

I saved and rebuilt the game.

Another error in the ActorAnimationManager.cs file:

System.NullReferenceException was unhandled

float distance = Vector2.Distance((_actorComponent.SceneObject.SceneGraph.Camera as T2DSceneCamera).Position, _actorComponent._animatedSprite.Position);

So I soldiered on dissecting a little more and commented these lines out.

It worked! Here is the code I used to load in the level.
Game.Instance.SceneLoader.Load(@"datalevelsdemo_modified2.txscene");

// set the parallax manager's target object
T2DSceneCamera camera = TorqueObjectDatabase.Instance.FindObject<T2DSceneCamera>("Camera");
ParallaxManager.Instance.ParallaxTarget = camera;
_sceneGraph = camera.SceneGraph as T2DSceneGraph;


GUIStyle playStyle = new GUIStyle();
GUISceneview play = new GUISceneview();
play.Name = "PlayScreen";
play.Style = playStyle;
play.Camera = camera;

GUICanvas.Instance.SetContentControl(play);
PlatformerDemoGUI.Instance.GUI.Folder = GUICanvas.Instance;
Here’s a small vid just to show:



I know this isn’t perfect but I’m not a coder and was wondering if anyone had been investigating this? There are obvious issues with the camera being referenced and at first I though this was down to the scene file not saving the cameras name, so any reference made to it was null?

I think a coding Guru is needed to clear things up for us all!Hopefully this is a start, although you do loose some functionality from the PSK.

#1
09/03/2010 (4:56 pm)
That is actually pretty good. Its much farther than I got. Im not the code guru that you need but. How did you do this did you merge the GUI with th PSK? In any event after you and the community completes this a small tutorial on how to do this would be awesome(and save us from the plague).
#2
09/03/2010 (5:08 pm)
Ha ha!;-)

I basically used the PSK demo and then used Henry Shilling Gamekit and the the splash screen tutorial from Dro Sarhadian to form a base.

I then just used trial and error to find what was causing the exceptions. The PSK demo uses some components which don't mix too well.

I'm not sure the way I did it, is the best way though.

By all means I can upload this for everyone? It maybe a start at least.

I would like a savvy code monkey to make sure we're going in the right direction :-)
#3
09/03/2010 (5:26 pm)
This is a good direction. The platformer starter kit usually crops up bugs here and there, like null reference errors, when you start changing things around. Before commenting out lines, try adding

if (YourObject != null) before those offending lines that threaten to break your code. Thats just basic coding 101, not to say you need to be a code monkey to get this stuff done, you are obviously doing very well!
#4
09/03/2010 (5:48 pm)
Ah Mr O'Reagan, your a smooth talker ;-)

I'll try your suggestion, I'm trying to get a solid framework built before I start building my project!

Hopefully between we can add a solid tutorial to the community pages.

Out of intrest have you used the PSK a lot?

#5
09/03/2010 (7:27 pm)
Yeah, Project Gert is currently using the framework. Its alot of fun!