Airplane tutorial question, accessing the WorldCam elsewhere..
by Ezra · in Torque X 2D · 12/07/2008 (3:43 pm) · 1 replies
I completed the Airplane tutorial and got it all functioning, I figured I'd try adding more stuff to it in order to learn how things work, but I'm having trouble with even the simplest of things...
What I'd like to do is be able to access the WorldCam that is created in Game.cs inside the BeginRun() ..method?..function?
I'd like to be able to set/get its properties (properties of a T2DSceneCamera) from within the other script files, for example AirplaneControlComponent.cs
I'm thinking I need to do something like this,
WorldCam = TorqueObjectDatabase.Instance.FindObject("WorldCam");
and then be able to do this,
WorldCam.Zoom = whatever
I'm trying to adjust the WorldCam's zoom in the ProcessTick function/method where the plane gets scaled up and down using the altitude variables.
Any ideas, any tutorials that cover the ways youre supposed to do that stuff? Doing what I listed above gives me a NullReferenceException and says to use the new keyword to create an instance, but why would I want to do that when I know that the WorldCam already exists..
Now I'm thinking maybe I add something to Game.cs that makes WorldCam accessible everywhere, maybe in the public properties area? This is really confusing, and the more I look at this C# stuff the more it seems like it would be easier if it was all visually laid out instead of typing it all, being able to connect lines to ins and outs and see what can access what and snap components onto things..
What I'd like to do is be able to access the WorldCam that is created in Game.cs inside the BeginRun() ..method?..function?
I'd like to be able to set/get its properties (properties of a T2DSceneCamera) from within the other script files, for example AirplaneControlComponent.cs
I'm thinking I need to do something like this,
WorldCam = TorqueObjectDatabase.Instance.FindObject
and then be able to do this,
WorldCam.Zoom = whatever
I'm trying to adjust the WorldCam's zoom in the ProcessTick function/method where the plane gets scaled up and down using the altitude variables.
Any ideas, any tutorials that cover the ways youre supposed to do that stuff? Doing what I listed above gives me a NullReferenceException and says to use the new keyword to create an instance, but why would I want to do that when I know that the WorldCam already exists..
Now I'm thinking maybe I add something to Game.cs that makes WorldCam accessible everywhere, maybe in the public properties area? This is really confusing, and the more I look at this C# stuff the more it seems like it would be easier if it was all visually laid out instead of typing it all, being able to connect lines to ins and outs and see what can access what and snap components onto things..
About the author
Torque Owner Ezra
I removed the line T2DSceneCamera WorldCam = new T2DSceneCamera();
and then put this up outside of BeginRun(),
public static T2DSceneCamera WorldCam = new T2DSceneCamera();
Then in AirplaneControlComponent.cs I added this line under where the airplane size is adjusted
Game.WorldCam.Zoom = (float)Math.Pow(1.5f,-_altitude.Value*0.1);
now when diving or pulling up the camera zooms in and out a bit...