Game Development Community

Setting the WorldLimit on the default T2DSceneCamera

by Michael Vargas · in Torque X 2D · 02/26/2007 (8:37 pm) · 7 replies

Before I dive too far in, I'm curious about the best way to approach setting the world limits on the default T2DSceneCamera.

Since I can't access this camera from TGBX (please correct me if I'm wrong), the only way I know to initialize its WorldLimit property is to modify the XML manually (a recipe for disaster when using the TGBX in conjunction with this, since all manual changes will get wiped every time the scene is saved in TGBX) to add:

true

within the tag. I know of no direct way to accomplish this programmatically, since the camera is already created by the time I would need to access it to set its creation properties. Assuming I can get this working, I still need to know where and how I should go about implementing the OnWorldLimit delegate. Even further, will this conflict with the fact that I have my camera mounted to a link point on my player?

My only thoughts so far are to work around this perceived limitation, creating a separate component called PlayerFollowCamera (or something) which will implement the camera-following behavior as well as enforcing the world limits manually.

Is there a much better approach that I'm overlooking?

Thanks,
Mike

#1
02/26/2007 (9:28 pm)
@Mike - I'm not sure if this works in the open beta version of TGBX, but have you tried setting the "view limits" on the camera? You might be able to access them if you go to the edit pane when you don't have any particular object selected in TGBX.
#2
02/26/2007 (10:25 pm)
Ah, thank you for that bit of insight -- I had no idea there was a way to modify the camera's properties from TGBX, probably because I usually have something selected or else I'm in the material editor.

Unfortunately I can only set the X, Y, Width, and Height properties, as well as checkboxes specifying Fixed Width and Fixed Height. Is there a different version of TGBX that I'm not aware of? A closed beta or something that you're implicitly referring to? If so, I'd like to get my hands on that.
#3
02/27/2007 (6:47 am)
I'm fairly certain that TGBX overwrites certain parts of the XML, but doesn't blanketly overwrite anything that was manually added. I seem to recall adding names to T2DSpawnObjects which wasn't something you could set in TGBX and they persisted through saves both in TGBX and VS.net. Only certain things are getting reset for some reason.

www.linkedin.com/img/webpromo/btn_viewmy_160x25.gif

www.mmogamedev.info/images/imgdc_ad1.gif
#4
02/27/2007 (8:13 am)
TGBX overwrites the entire xml file every time you save it. If you put information in your xml file that TGBX is not able to deserialize then it will be gone when TGBX serializes the scene data to the xml. TGBX is not searching through your xml file looking for the lines to update. The entire scene is serialized into a new xml document in memory every time you save. That new xml document in memory then overwrites the old xml document on the drive.
#5
02/27/2007 (8:31 am)
@Mike - See if you can set the UseCameraWorldLimits, CameraWorldLimitMin, and CameraWorldLimitMax properties of T2DSceneGraph.Instance.DefaultCamera via C# code.

Also, to get components hooked to your camera, you can try just creating a new camera. This worked for me:
T2DSceneCamera MyCamera = T2DSceneGraph.Instance.DefaultCamera.Clone() as T2DSceneCamera;
MyCamera.Components.AddComponent(new T2DPhysicsComponent());
ScrollerCameraComponent CameraComponent = new ScrollerCameraComponent();
MyCamera.Components.AddComponent(CameraComponent);
TorqueObjectDatabase.Instance.Register(MyCamera);
T2DSceneGraph.Instance.Camera = MyCamera;
#6
02/27/2007 (9:25 am)
@Ben - I double checked and I am in fact setting an object name for my T2DSpawnObject's which I set directly in the XML because TGBX doesn't have a spot to enter them. This is persisting through various changes through TGBX, so TGBX either can't do a blanket rewrite or someone's been slipping me some shrooms.

www.linkedin.com/img/webpromo/btn_viewmy_160x25.gif

www.mmogamedev.info/images/imgdc_ad1.gif
#7
02/27/2007 (6:22 pm)
...then you need to stay off the shrooms.

Just because TGBX doesn't have a field for something doesn't mean it doesn't read/write it from memory. Discovering which things these are is going to be unreliable in the long term and based entirely on trial and error. Try peppering your txscene file with xml comments all over creation. Notice when you save the file they are all eliminated. If TGBX is not programmed to read a value into memory from your xml then that value will be gone when it serializes the scene. End of story.