This is a very rough guide/outline that I put together for my personal use to help me understand TGBX better and faster – you may or may not find this useful
. I don’t claim to have come up with all of this – most, if not all of this material, is derived from:
This document assumes knowledge of the contents of the first two sources, and actually depends heavily on them
. It’s basically just the Blaster/Microbes tutorials minus specifics. I thought that it might be helpful to lay out the things described there more generally.
I’d love to hear what you think about this document – feel free to leave a comment
.
Thank you so much to GarageGames and Microsoft for this amazing product, and to the GarageGames and XNA communities for all the help that you continue to give!
Personally, I like everything on one big page, and if there’s anything I need, I just hit Ctrl+F from within Firefox then type in the keyword I’m looking for, then press Ctrl+G as needed. Very primitive, but it works for me
.
You may want to check the Remove On Finished checkbox.
…you may want to add the following piece of code:
static public Game GameInstance
{
get { return _myGame; }
}
T2DSceneObject _gameObject;
public T2DSceneObject GameObject
{
get { return _gameObject; }
set { _gameObject = value; }
}
public void SomePublicMethod()
{
// look up the template for the object;
// here, SceneObjectTemplate would correspond to the name we gave to the template earlier in TGBX
T2DSceneObject sceneObjectTemplate = TorqueObjectDatabase.Instance.FindObject("SceneObjectTemplate");
if (sceneObjectTemplate != null)
{
// clone the template to create the object
_gameObject = (T2DSceneObject)sceneObjectTemplate.Clone();
// process _gameObject further here...
// register our object with the TorqueObjectDatabase
TorqueObjectDatabase.Instance.Register(_gameObject);
}
}
Alternatively, one can also write (NOT TESTED YET and COULD BE INCORRECT):
public void SomePublicMethod()
{
// clone the template to create the object
_gameObject = TorqueObjectDatabase.Instance.CloneObject("sceneObjectTemplate");
// process _gameObject further here...
// register our object with the TorqueObjectDatabase
TorqueObjectDatabase.Instance.Register(_gameObject);
}
Note that sceneObjectTemplate.Clone() returns an Object object, so it needs a cast, while TorqueObjectDatabase.Instance.CloneObject
For this, the Torque X API.chm help file is your best source of information. Basically, this will allow you to do in code the changes you make to scene objects within the TGBX editor.
Within a method (maybe within // process _gameObject further here...),
_gameObject.Position = new Microsoft.Xna.Framework.Vector2(desiredX, desiredY);
or
_gameObject.Position = SceneObject.Position;
where SceneObject refers to the scene object to which the component is attached to.
_gameObject.Layer = SceneObject.Layer + n; // n an integer
_gameObject.Rotation = 180.0f;
_gameObject.CollisionsEnabled = true;
_gameObject.Collision.CollidesWith = TorqueObjectDatabase.Instance.GetObjectType("objectType");
_gameObject.Collision.ResolveCollision = T2DPhysicsComponent.KillCollision;
_gameObject.Physics.Velocity = new Vector2(0.0f, -80.0f); _gameObject.Physics.VelocityY = TorqueUtil.GetRandomFloat(5.0f, 15.0f);
Within the BeginRun method in the region Private, protected, internal methods in Game.cs:
SceneLoader.Load(@"data\levels\sceneNameHere.txscene");
This line may be followed by Public Methods that initialize the level (probably concerning Scene Objects).
InputMap inputMap = PlayerManager.Instance.GetPlayer(0).InputMap;
int gamepadId = InputManager.Instance.FindDevice("gamepad0");
if (gamepadId >= 0)
{
inputMap.BindMove(gamepadId, (int)XGamePadDevice.GamePadObjects.A, MoveMapTypes.Button, 0);
}
int keyboardId = InputManager.Instance.FindDevice("keyboard");
if (keyboardId >= 0)
{
inputMap.BindMove(keyboardId, (int)Keys.Space, MoveMapTypes.Button, 0);
}
// tell the engine to call our ProcessTick method every clock tick.
ProcessList.Instance.AddTickCallback(Owner, this);
Again, I highly recommend that you refer to the Torque X API.chm help file – it will really help in understanding the inputMap.BindMove method.
if (move != null && move.Buttons[0].Pushed == true)
{
_React();
}
[TorqueXmlSchemaType(DefaultValue="15")]
public float FieldName
{
get { return _fieldName; }
set { _fieldName = value; }
}
[TorqueXmlSchemaType(DefaultValue="8")]
public float AnotherField
{
get { return _anotherField; }
set { _anotherField = value; }
}
public override void CopyTo(TorqueComponent obj)
{
base.CopyTo(obj);
ComponentNameHere obj2 = (ComponentNameHere)obj;
obj2.FieldName = FieldName;
obj2.AnotherField = AnotherField;
}
A more complete discussion on this matter is available in the Torque X Forums.
float GameObjectX = Game.GameInstance.GameObject.Position.X;