Understanding the Sandbox - ml-t2d/wiki-work GitHub Wiki
Introduction
After you have downloaded the binary release or compiled the source, running Torque2D.exe or Torque2D.app will show you something like this:
Insert Image
This is the Sandbox and one of its toys.
The Sandbox can be thought of as a container that contains various toys. The toys are simple demonstrations of various features of T2D. Technically, the Sandbox is nothing more than a specifically designed module that loads toys, with each toy being an individual module as well. For more information on the module system, see the Module Guide.
How to use the Sandbox
As the contents of the Sandbox can change over time, depending on future releases, we will not go into specific detail on each toy but instead provide a general overview of Sandbox functionality.
Again, the Sandbox is a container and it displays the default or currently loaded toy. Input is handled through the mouse or touch, depending on the platform. In addition to interacting with the Scene by touch, or mouse clicks, or dragging - there is a row of buttons at the bottom of the screen.
Insert Image
The first button switches the input mode.
The second button restarts the toy.
The third button reloads the toy.
The fourth button opens up the console.
Insert Image
The console provides helpful text based output of the engine and game state. If there are any problems, often an error message appears here. It is also possible when writing scripts to have it output text to the console, which is useful for debugging purposes. All contents of the console are also saved to the console.log file in the root level Torque2D folder after the engine is shut down.
The fifth button opens up the toolbox. There are a lot of different options available through this screen.
Insert Image
The left column presents a list of all available toys that you can select from. The list can also be sorted into different categories to make finding a specific toy easier. This list is automatically generated when the Sandbox module is loaded, so a new toy can be added to the list simply by restarting the engine.
The middle column displays toy specific options that allow you to tweak parameters.
The right column has a list of general debug options or modes. The display resolution or background color of the canvas can also be changed here.
Adding Toys to the Sandbox
Creating your own toys and adding them to the Sandbox is a great way to prototype game ideas, built a test case that highlights a bug, or otherwise share content with others in the community. Creating your own toy for the Sandbox is quite simple.
-
Since a toy is a module, it goes in the modules folder.
-
Typically when creating the folder structure for the module, the folder name is (something)Toy, as seen in many of the examples included with T2D. This is not a requirement though, you can use any name you wish.
-
When creating the module definition file, assign the type field with
toy
. And that's it actually - this one field allows the Sandbox to find your module and include it with the rest of the toys. As an example:
<ModuleDefinition
ModuleId="AlphaBlendToy"
VersionId="1"
Description="Show the sprite alpha blending feature."
Dependencies="ToyAssets=1"
Type="toy"
ToyCategoryIndex="3"
ScriptFile="main.cs"
CreateFunction="create"
DestroyFunction="destroy"/>
-
Toys can be sorted into different categories through the custom field ToyCategoryIndex. 0 is for "All", 1 for "Physics", 2 for "Features", 3 for "Stress Testing", 4 for "Fun and Games", 5 is for "Custom", and 6 for "Experiments".
-
If want your toy to use any of the default assets that come with T2D, make sure to set the Dependencies field to "ToyAssets=1".
-
Remember when making toys that the Sandbox handles the SceneWindow and Scene. When you want to add objects to your scene, it is named SandboxScene by default.