First T2D Tutorial - Stuck
by David Taylor · in Torque Game Engine · 03/19/2006 (10:59 pm) · 2 replies
As embarrassing as it is to admit it, the first piece of code in the BasicTutorial.pdf has me stumped. As far as I can tell, my game.cs scripting should read like this:
//---------------------------------------------------------------------------------------------
// Torque 2D.
// Copyright (C) GarageGames.com, Inc.
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
// setupT2DScene
// This function is the starting point for all game specific code.
//---------------------------------------------------------------------------------------------
function setupT2DScene()
{
// Create our scenegraph
new t2dSceneGraph(t2dScene);
// Associate Scenegraph with Window.
sceneWindow2D.setSceneGraph( t2dScene );
// Set the current camera position
sceneWindow2D.setCurrentCameraPosition("0 0 100 75");
// add an image to the screen
datablock t2dImageMapDatablock(playershipImageMap)
{
imageMode = full;
imageName = "~/data/images/playerShip";
$player = new t2dStaticSprite() { scenegraph = t2dScene; };
$player.setPosition("-35 0");
$player.setSize("14 7");
$player.setImageMap(playershipImageMap);
};
}
That is supposed to draw an image, (playerShip.png), to the screen, but it doesn't. As the documentation doesn't show the complete code required after each step, I may well have put portions in the wrong area, although the following has nothing drawing either:
//---------------------------------------------------------------------------------------------
// Torque 2D.
// Copyright (C) GarageGames.com, Inc.
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
// setupT2DScene
// This function is the starting point for all game specific code.
//---------------------------------------------------------------------------------------------
function setupT2DScene()
{
// Create our scenegraph
new t2dSceneGraph(t2dScene);
// Associate Scenegraph with Window.
sceneWindow2D.setSceneGraph( t2dScene );
// Set the current camera position
sceneWindow2D.setCurrentCameraPosition("0 0 100 75");
// add an image to the screen
datablock t2dImageMapDatablock(playershipImageMap)
{
imageMode = full;
imageName = "~/data/images/playerShip";
};
$player = new t2dStaticSprite() { scenegraph = t2dScene; };
$player.setPosition("-35 0");
$player.setSize("14 7");
$player.setImageMap(playershipImageMap);
}
Can anyone explain what I've done wrong here?
//---------------------------------------------------------------------------------------------
// Torque 2D.
// Copyright (C) GarageGames.com, Inc.
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
// setupT2DScene
// This function is the starting point for all game specific code.
//---------------------------------------------------------------------------------------------
function setupT2DScene()
{
// Create our scenegraph
new t2dSceneGraph(t2dScene);
// Associate Scenegraph with Window.
sceneWindow2D.setSceneGraph( t2dScene );
// Set the current camera position
sceneWindow2D.setCurrentCameraPosition("0 0 100 75");
// add an image to the screen
datablock t2dImageMapDatablock(playershipImageMap)
{
imageMode = full;
imageName = "~/data/images/playerShip";
$player = new t2dStaticSprite() { scenegraph = t2dScene; };
$player.setPosition("-35 0");
$player.setSize("14 7");
$player.setImageMap(playershipImageMap);
};
}
That is supposed to draw an image, (playerShip.png), to the screen, but it doesn't. As the documentation doesn't show the complete code required after each step, I may well have put portions in the wrong area, although the following has nothing drawing either:
//---------------------------------------------------------------------------------------------
// Torque 2D.
// Copyright (C) GarageGames.com, Inc.
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
// setupT2DScene
// This function is the starting point for all game specific code.
//---------------------------------------------------------------------------------------------
function setupT2DScene()
{
// Create our scenegraph
new t2dSceneGraph(t2dScene);
// Associate Scenegraph with Window.
sceneWindow2D.setSceneGraph( t2dScene );
// Set the current camera position
sceneWindow2D.setCurrentCameraPosition("0 0 100 75");
// add an image to the screen
datablock t2dImageMapDatablock(playershipImageMap)
{
imageMode = full;
imageName = "~/data/images/playerShip";
};
$player = new t2dStaticSprite() { scenegraph = t2dScene; };
$player.setPosition("-35 0");
$player.setSize("14 7");
$player.setImageMap(playershipImageMap);
}
Can anyone explain what I've done wrong here?
About the author
#2
I just wish the tutorial had said something similar, lol - it never even hinted to adding scripting to datablocks.cs.
Thanks for the link - I'll be referring to that quite a lot in the future. :)
03/20/2006 (10:40 am)
Thanks, Dave. That worked. :)I just wish the tutorial had said something similar, lol - it never even hinted to adding scripting to datablocks.cs.
Thanks for the link - I'll be referring to that quite a lot in the future. :)
Torque Owner Dave D
Try something like this:
function setupT2DScene() { // Create our scenegraph new t2dSceneGraph(t2dScene); // Associate Scenegraph with Window. sceneWindow2D.setSceneGraph( t2dScene ); // Add custom game code here... createPlayer(); } // this function probably should go in it's own file, but that's really your preference. function createPlayer() { $player = new t2dStaticSprite() { scenegraph = t2dScene; }; $player.setPosition("-35 0"); $player.setSize("14 7"); $player.setImageMap(playershipImageMap); }and in ~/data/content/datablocks.cs
datablock t2dImageMapDatablock(playershipImageMap) { imageMode = full; imageName = "~/data/images/playerShip"; filterPad = false; };Now I haven't tried this, but it should work...
I just read the PDF, and I think possibly could use more clarification there.
By the way, there are more tutorials on TDN. I suggest the platformer tutorial, it's been updated and you really learn alot from it.