<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>

<channel>
	<title>Game Programming at scriptedfun &#187; tgbx</title>
	<atom:link href="http://www.scriptedfun.com/category/tgbx/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scriptedfun.com</link>
	<description>Game Programming for Beginners: Video Tutorials, Source Code, and Articles</description>
	<lastBuildDate>Thu, 11 Sep 2008 17:45:09 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/</creativeCommons:license>
		<item>
		<title>Torque X Notes</title>
		<link>http://www.scriptedfun.com/torque-x-notes/</link>
		<comments>http://www.scriptedfun.com/torque-x-notes/#comments</comments>
		<pubDate>Wed, 13 Jun 2007 10:10:46 +0000</pubDate>
		<dc:creator>Chuck</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[gamedev]]></category>
		<category><![CDATA[garagegames]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[tgbx]]></category>
		<category><![CDATA[torque]]></category>
		<category><![CDATA[torquex]]></category>
		<category><![CDATA[xna]]></category>

		<guid isPermaLink="false">http://www.scriptedfun.com/torque-x-notes/</guid>
		<description><![CDATA[Torque X Notes at scriptedfun.com
Version 0.1 &#8211; June 13, 2007
This is a very rough guide/outline that I put together for my personal use to help me understand TGBX better and faster &#8211; you may or may not find this useful  . I don&#8217;t claim to have come up with all of this &#8211; most, [...]]]></description>
			<content:encoded><![CDATA[<h3><a href="http://www.garagegames.com/products/torque/x/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.garagegames.com');">Torque X</a> Notes at <a href="http://www.scriptedfun.com/">scriptedfun.com</a></h3>
<h4>Version 0.1 &#8211; June 13, 2007</h4>
<p>This is a very rough guide/outline that I put together for my personal use to help me understand TGBX better and faster &#8211; you may or may not find this useful <img src='http://www.scriptedfun.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . I don&#8217;t claim to have come up with all of this &#8211; most, if not all of this material, is derived from:</p>
<ul>
<li><b>TGBX Documentation</b></li>
<li><b>Torque X User&#8217;s Guide</b></li>
<li>(the often overlooked but very useful) <b>Torque X API.chm</b></li>
<li><a href="http://www.microsoft.com/events/series/msdnvisualcsharp.mspx" onclick="javascript:pageTracker._trackPageview ('/outbound/www.microsoft.com');">Microsoft webcasts</a></li>
<li><a href="http://www.garagegames.com/mg/forums/result.area.php" onclick="javascript:pageTracker._trackPageview ('/outbound/www.garagegames.com');">GarageGames forums</a></li>
<li><a href="http://forums.xna.com/" onclick="javascript:pageTracker._trackPageview ('/outbound/forums.xna.com');">XNA forums</a></li>
</ul>
<p>This document assumes knowledge of the contents of the first two sources, and actually depends heavily on them <img src='http://www.scriptedfun.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . It&#8217;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.</p>
<p>I&#8217;d love to hear what you think about this document &#8211; feel free to leave a comment <img src='http://www.scriptedfun.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<p>Thank you so much to <a href="http://www.garagegames.com/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.garagegames.com');">GarageGames</a> and <a href="http://msdn2.microsoft.com/en-us/library/bb200104.aspx" onclick="javascript:pageTracker._trackPageview ('/outbound/msdn2.microsoft.com');">Microsoft</a> for this amazing product, and to the <a href="http://www.garagegames.com/mg/whatsnew/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.garagegames.com');">GarageGames</a> and <a href="http://creators.xna.com/" onclick="javascript:pageTracker._trackPageview ('/outbound/creators.xna.com');">XNA</a> communities for all the help that you continue to give! <img src='http://www.scriptedfun.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<h4>How To Use This Document</h4>
<p>Personally, I like everything on one big page, and if there&#8217;s anything I need, I just hit <b>Ctrl+F</b> from within <a href="http://www.mozilla.com/en-US/firefox/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.mozilla.com');">Firefox</a> then type in the keyword I&#8217;m looking for, then press <b>Ctrl+G</b> as needed. Very primitive, but it works for me <img src='http://www.scriptedfun.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<h4>GUI Matters</h4>
<h5>First Steps</h5>
<ol>
<li>Make a new project using the <b>StarterGame</b> template in Visual C# Express, and build the solution.</li>
<li>Start TGBX and load <b>StarterGame.txproj</b>.</li>
<li>Save the scene as <b><i>sceneNameHere</i>.txscene</b>.</li>
<li>Materials may be imported simply by dragging images into TGBX.</li>
</ol>
<h5>Setting-up Animated Sprites</h5>
<ol>
<li>Click on the Animation check box.</li>
<li>Adjust the cell fields as appropriate.</li>
<li>Click <b>Create a new Animation</b>.</li>
<li>Click <b>Add all frames from the image (green button)</b></li>
<li>Change the <b>Cycle Animation</b> checkbox as appropriate.</li>
<li>Adjust the <b>Frames Per Second</b>.</li>
<li><b>Save</b> the animation.</li>
</ol>
<h5>Defining Object Types</h5>
<ol>
<li>Make sure that no objects are selected in the scene.</li>
<li>Go to the <b>Edit Pane</b>&#8217;s <b>Scene Data</b> tab.</li>
<li>Type a name in the <b>Object Types</b> text box, then click the green button to make it register.</li>
</ol>
<h5>Defining Templates</h5>
<h6>General Directions</h6>
<ol>
<li>From the <b>Create</b> pane, drag the material for the template into the scene (may be outside the camera area if you don&#8217;t want it to appear immediately at the start of the game).</li>
<li>You may manipulate the material as needed using the <b>Edit Pane</b>&#8217;s <b>Scene Object tab</b>.</li>
<li>Give the template a name using the <b>Scripting tab</b> of the <b>Edit pane</b>.</li>
<li>You may mark the template using one of the <b>object types</b> you have defined.</li>
<li>Check the <b>Template</b> box in the <b>Scripting</b> tab.</li>
<li>You may change the template&#8217;s collision detection polygon or its world limits.</li>
<li>If appropriate, enable/disable <b>Pool With Components</b></li>
<li>You may add/adjust the <b>components</b> from the <b>Edit</b> pane. Items of particular interest:
<ul>
<li><b>WorldLimitResolveCollision</b> in <b>T2DWorldLimitComponent</b></li>
<li><b>CollidesWith</b> in <b>T2DCollisionComponent</b></li>
</ul>
</li>
</ol>
<h5>For animations</h5>
<p>You may want to check the <b>Remove On Finished</b> checkbox.</p>
<h4>C# Matters</h4>
<h5>In Game.cs&#8230;</h5>
<p>&#8230;you may want to add the following piece of code:</p>
<pre>
static public Game GameInstance
{
	get { return _myGame; }
}
</pre>
<h5>Putting Scene Objects in Variables</h5>
<ol>
<li>In the region <b>Private, protected, internal fields</b>, add:
<pre>T2DSceneObject _gameObject;</pre>
</li>
<li>In the region <b>Public properties, operators, constants, and enums</b>, add:
<pre>
public T2DSceneObject GameObject
{
	get { return _gameObject; }
	set { _gameObject = value; }
}
</pre>
</li>
<li>Typically, one would access <tt>_gameObject</tt> from a method within the region <b>Public Methods</b>, whose contents are typically called from the <b>Private, protected, internal methods</b> region&#8217;s <b>BeginRun</b> method, where, VERY simply speaking, game code execution starts. Usage of <tt>_gameObject</tt> would probably work like this:
<pre>
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<T2DSceneObject>("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);
	}
}
</pre>
<p>Alternatively, one can also write (<b><i>NOT TESTED YET and COULD BE INCORRECT</i></b>):</p>
<pre>
public void SomePublicMethod()
{
	// clone the template to create the object
	_gameObject = TorqueObjectDatabase.Instance.CloneObject<T2DSceneObject>("sceneObjectTemplate");

	// process _gameObject further here...

	// register our object with the TorqueObjectDatabase
	TorqueObjectDatabase.Instance.Register(_gameObject);
}
</pre>
<p>Note that <tt>sceneObjectTemplate.Clone()</tt> returns an <tt>Object</tt> object, so it needs a cast, while <tt>TorqueObjectDatabase.Instance.CloneObject<T2DSceneObject></tt> returns a <tt>T2DSceneObject</tt>.
</li>
</ol>
<h5>Manipulating Scene Objects from Code</h5>
<p>For this, the <b>Torque X API.chm</b> 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.</p>
<h6>Setting a scene object&#8217;s position</h6>
<p>Within a method (maybe within <tt>// process _gameObject further here...</tt>),</p>
<pre>
_gameObject.Position = new Microsoft.Xna.Framework.Vector2(desiredX, desiredY);
</pre>
<p>or</p>
<pre>
_gameObject.Position = SceneObject.Position;
</pre>
<p>where <tt>SceneObject</tt> refers to the scene object to which the component is attached to.</p>
<h6>Setting a scene object&#8217;s layer</h6>
<pre>
_gameObject.Layer = SceneObject.Layer + n;	// n an integer
</pre>
<h6>Setting a scene object&#8217;s rotation</h6>
<pre>
_gameObject.Rotation = 180.0f;
</pre>
<h6>Enabling/disabling collisions</h6>
<pre>
_gameObject.CollisionsEnabled = true;
</pre>
<h6>T2DCollisionComponent</h6>
<pre>
_gameObject.Collision.CollidesWith = TorqueObjectDatabase.Instance.GetObjectType("objectType");
_gameObject.Collision.ResolveCollision = T2DPhysicsComponent.KillCollision;
</pre>
<h6>T2DPhysicsComponent</h6>
<pre>
_gameObject.Physics.Velocity = new Vector2(0.0f, -80.0f);
_gameObject.Physics.VelocityY = TorqueUtil.GetRandomFloat(5.0f, 15.0f);
</pre>
<h5>Loading Levels</h5>
<p>Within the <b>BeginRun</b> method in the region <b>Private, protected, internal methods</b> in <b>Game.cs</b>:</p>
<pre>
SceneLoader.Load(@"data\levels\sceneNameHere.txscene");
</pre>
<p>This line may be followed by <b>Public Methods</b> that initialize the level (probably concerning <b>Scene Objects</b>).</p>
<h5>Adding Components</h5>
<ol>
<li>Add a new <b>T2DComponent</b> called <b><i>ComponentNameHere</i>.cs</b> from Game Studio Express.</li>
<li>Add fields such as <tt>float _fieldName;</tt> relevant to the component in the region <b>Private, protected, internal fields</b>.</li>
<li>Add methods in the region <b>Private, protected, internal methods</b>.</li>
<li>If you want your component to accept input, you may want to add code similar to the following in the <b>Private, protected, internal methods</b> region, in the <tt>_OnRegister</tt> method, before the <tt>return true</tt> statement:
<pre>
	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);
</pre>
<p>Again, I highly recommend that you refer to the <b>Torque X API.chm</b> help file &#8211; it will really help in understanding the <tt>inputMap.BindMove</tt> method.
</li>
<li>To make the game to actually react to the user input, you will need to add the following to the <tt>ProcessTick</tt> method in the <b>Public Methods</b> region:
<pre>
	if (move != null &#038;&#038; move.Buttons[0].Pushed == true)
	{
		_React();
	}
</pre>
</li>
<li>We can make properties for the fields defined earlier, and make them editable in TGBX using code similar to the following within the <b>Public properties, operators, constants, and enums</b> region:
<pre>
	[TorqueXmlSchemaType(DefaultValue="15")]
	public float FieldName
	{
		get { return _fieldName; }
		set { _fieldName = value; }
	} 

	[TorqueXmlSchemaType(DefaultValue="8")]
	public float AnotherField
	{
		get { return _anotherField; }
		set { _anotherField = value; }
	}
</pre>
</li>
<li>In order to make templates using this component clonable, we will need to modify the <tt>CopyTo</tt> method in the <b>Public Methods</b> region as follows:
<pre>
	public override void CopyTo(TorqueComponent obj)
	{
		base.CopyTo(obj);

		ComponentNameHere obj2 = (ComponentNameHere)obj;

		obj2.FieldName = FieldName;
		obj2.AnotherField = AnotherField;
	}
</pre>
<p><a href="http://www.garagegames.com/mg/forums/result.thread.php?qt=63260" onclick="javascript:pageTracker._trackPageview ('/outbound/www.garagegames.com');">A more complete discussion on this matter</a> is available in the <a href="http://www.garagegames.com/mg/forums/result.forum.php?qf=192" onclick="javascript:pageTracker._trackPageview ('/outbound/www.garagegames.com');">Torque X Forums</a>.
</li>
</ol>
<h5>Working Within Components</h5>
<ol>
<li>To access public properties defined in <b>Game.cs</b> from within a component, you may use <tt>Game.GameInstance</tt>. For example, if the <tt>T2DSceneObject GameObject</tt> property is defined in <tt>Game.cs</tt>, you may use the following code:
<pre>
float GameObjectX = Game.GameInstance.GameObject.Position.X;
</pre>
</li>
<li>To access the scene object to which the component is attached to, you may use <tt>SceneObject</tt>.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.scriptedfun.com/torque-x-notes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/</creativeCommons:license>
	</item>
	</channel>
</rss>
