Torque Beginners Tutorial
From TorqueWiki
Contents |
[edit] Links
[edit] Other Tutorials
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=12721
[edit] Tutorial Summary
[edit] Start Demo
- Goto directory:
- (Windows) Torque SDK: Arbeitsplatz->Programme->Torque->SDK
or for Unix:
- ~/torque/Torque1.5.2-Linux/example
main.cs should start the tutorial.base:
$defaultGame = "tutorial.base";
NOTE: Do not declair $defaultGame more than once, variables do not get overwritten but concatinated. This will lead to script and gui files found multiple time in different mod directories.
[edit] Console
- click on the console icon
- look at history
- type quit();
[edit] Set Up Game Files
- Copy tutorial.base directory, name the copy 'GameOne'
- In main.cs change: $defaultGame = "GameOne";
- Inspect directory: textures, script files .cs .dso
[edit] Tools
[edit] Save Misssion
- File>Save Mission As
- Change the folder to GameOne/data/missions
- save your work as 'GameOneMission.mis'
- Control GameOne/data/missions was really written, see Linux issues (all is written to.garagegames in home dir)
- if not> cp flat.* to GameOne.* and reopen it
NOTE: See the point save mission below (check name in main).
[edit] World Editor (Hotkey: F2)
- Window>World Editor
- Camera>Toggle Camera (Hotkey: Alt C)
- Looking around: right-click and drag in the window
- Moving around: keys W, A, S, and D
- third person mode: holding the right mouse button down and pressing the Tab key
- Detach camera from player by selecting Drop Camera at Player (Hotkey: Alt Q)
- Change the speed of camera movement by pressing Shift 1-7 (see the Camera menu)
- Camera>Toggle Camera -> back to the player
[edit] Terrain Editor
- Window>Terrain Editor
- Colored squares are the affected area of the terrain
- Action menu: Adjust Height; try other points
- Ctrl-Z to undo Ctrl-R to redo
- Brush>Size 5x5
- Lighting Tools->Relight to update the szene lighting
- walk around: Camera>Toggle Camera
- If player under the ground: Camera>Drop Player at Camera (Hotkey: Alt W)
[edit] Terrain Texture Painter
- Window>Terrain Texture Painter
- Change checkerboard texture:
- Press the Change button under the checkerboard in the texture window on the right side
- select sand.jpg texture from GameOne/data/terrains and press Load
- Add Texture
- Click the Add... button under the empty texture area under your sand texture.
- Note: textures must be added sequentially in the Terrain Texture Painter.
- select patchy.jpg then press Load.
- Action menu -> automatically set to Paint Material.
- Paint with patchy.jpg; try a few brushes
- Note: No need to relight your scene when you paint terrain, only when changing the shape -> Lightmaps
Detail Texture
Detail texture is as a sort of underlying close-up texture.
- Window>World Editor Inspector
- select Terrain – TerrainBlock from the MissionGroup in the upper right window, which is called the Tree View.
- terrain data appears in the Inspector window below the Tree.
- In the Media section, find detailTexture, click the browse button (looks like 3 dots '...') on the right
- find GameOne/data/terrains/detail1.png
- Load (and Apply) and take a look at the ground.
[edit] Placing and Organizing Objects
[edit] World Editor Creator
- operate from camera view
- Window>World Editor Creator
- windows on the right side
- Top window is like in World Editor Inspector mode
- Creator window below lists available things to put in your mission
- World menu -> default mode for placing objects is Drop at Screen Center
Select and move:
- lower right window: expand Shapes -> Items
- Create TorqueLogo object in the center of the screen
- yellow box means selected
- ID number, and the (null) is a placeholder for the object's name
- X, Y, and Z axes can be grabbed for moving the object
- ALT-Shift-mouse Rotates
[edit] World Editor Inspector
Shapes
Smaller objects like the logos you just placed are called shapes in Torque and are based on .dts files.
- Window>World Editor Inspector
- Expand MissionGroup: sun, sky, ..., StaticShape object at the bottom is the logo
- Click on it -> Inspector : Change the scale from '1 1 1' to '1 1 10' and Apply
- hit ctrl-Z to undo the scaling
- Change the object name in the text input box next to the Apply buttonto 'logo' (and Apply).
- Place 3 logos on the map and name them logo
Interiors
The other main object type in Torque is called an interior, an object is big enough to walk in or on, and is based on a .dif file Interiors are similar to terrain in that you need to relight the scene to see their texture mapping correctly.
- expand the Interiors>GameOne>data>interiors folder in the World Editor Creator
- click on 'box' and our interior will appear at the screen center
- Select Relight Scene and you'll see the box's exterior
- move it upward along the Z axis until its bottom is at ground level
- move it over to a flat area
- go into Player mode and make sure you can get inside
- place one more logo inside the building by draging it into the building by hand
- Save your mission
Organizing Objects
Torque allows you to organize your objects into 'SimGroups'.
- Window->World Editor Creator
- expand MissionGroug
- In the Creator Window: expand Mission Objects and System
- Create two SimGroups: 'logos' and 'building'
- In the Tree view, drag each of your logo objects into that Logos SimGroup and the same for buidings
Spawn Sphere - the Initial Player Position
- Open the Inspector (F3): SimGroup - Player Drop Points -> Spawn Sphere
- Change the postion as it suits you (near your objects)
- Save the mission, exit and re-enter -> Player start at new position
[edit] Graphical User Interface (GUI)
A GUI consists of both the out of game menu system and the in game readouts of score, health,etc. .
[edit] GUI Editor
TGE provides GUI editor to create interface with new controls and scripts.
- return to the TGE main menu page, either by restarting torqueDemo, or by selecting File>Quit
- Select GUI Editor -> starts out with the current GUI loaded
- look at some of the objects in the Tree and their properties in the Inspector Dial
- New Control selection
- List of available controls
- GUI file selection
- list of GUIs available to edit... you're already in MainMenuGui, which is the one that comes up when you first run torqueDemo
- screen size selection
- select 640 x 480
Changing the Background Image
- Select the MainMenuGui in the Tree view
- Scroll down in the Inspector until you see the bitmap field in the Misc section
- to see the whole filename, so drag the divider between the left editor window and the right windows until you can see the whole bitmap filename
- change the filename from 'background' to 'gameonebg' and hit Apply
Adding and Removing Controls
- you can remove the Editor buttons from the top of the GUI by selecting and deleting them
- Add a button that starts our game: From the New Control dropdown button, select GuiButtonCtrl.
- Drag it to somewhere more pleasing, like maybe just below the GameOne title.
- Find the text field in the Misc section of the Inspector. In the blank field type 'Start' and hit Apply
- Find the command field in the Parent section, type in “loadMyMission();” and hit Apply
- Change the screen size dropdown from 640 x 480 to 1024 x 768.
- The button moves on background, switch back to 640 x 480.
- hange horizSizing and vertSizing to relative and hit Apply, try 1024 x 768 again.
- File>Save GUI..., change the folder to GameOne/client/ui and click the Save button
- Toggle the GUI Editor by hitting F10 and exit Torque.
- Now restart by running torqueDemo... you should come up with the new start page. Pressing the Start button now brings you into GameOne.
Adding the Score Counter to the play GUI
- Enter the mission, then enter the GUI Editor (F10)
- Select GuiTextCtrl from the New Control button
- name the control ScoreCounter (in the text box next to the Apply button).
- click on the profile button in the Parent section and select GuiBigTextProfile.
- In the General section enter Score: 0 in the text field, and hit Apply.
- change HorizSizing and VertSizing to relative.
- File>Save GUI...save the GUI as 'GameOne/client/ui/playGui.gui.'
- To Undo All: If you have any problems and you want to revert the MainMenuGui to its original state, just copy the tutorial.base/client/ui/MainMenuGui.gui over the gameone/client/ui/MainMenuGui.gui.
[edit] Scripting
NOTE: For Linux the filenames may have wrong case, add links in /torque/tge/example/GameOne/data/missions$ :
gameonemission.mis -> GameOne.mis gameonemission.ter -> GameOne.ter
- main.cs in our GameOne folder
- down to the bottom section 'LOAD MY MISSION'.
- find function definition for loadMyMission, we used as command for the Start button
Open file GameOne/server/logoitem.cs and add:
function TorqueLogoItem::onCollision(%this, %obj, %col)
{
if(%col.getClassName() $= "Player")
{
%client = %col.client;
%client.score++;
commandToClient(%client, 'SetScoreCounter', %client.score);
%obj.delete();
%logoCount = logos.getCount();
if(%logoCount > 0)
return;
// otherwise display victory screen
commandToClient(%client, 'ShowVictory', %client.score);
}
}
Create file GameOne/client/clientGame.cs:
function clientCmdSetScoreCounter(%score)
{
ScoreCounter.setText("Score:" SPC %score);
}
function clientCmdShowVictory(%score)
{
MessageBoxYesNo("You Win!",
"Would you like to restart the game ?",
"loadMyMission();",
"quit();");
}
Notice client functions with the same name as the second argument of the commandToClient server function, just added 'clientCmd' to the beginning of the name.
Load clientGame.cs' file in GameOne/main.cs. 'Client scripts' section of the function called initClient. At the bottom of that list, add the following line, which will load our file:
exec("./client/clientGame.cs");
