Game Development Community

Confusion about Datablocks and Objects

by Rogers Vizcaino · in Torque Game Builder · 08/02/2006 (12:28 pm) · 8 replies

Hi, i am trying this with no success

in my player.cs i have this:
function createPlayer()
{
   %player = new t2dStaticSprite() 
   { 
     scenegraph = sceneWindow2D.getSceneGraph();
     class=playerPlanes;
   };
   %player.setImageMap( playerNormal );
   %player.setSize( "87 114" );
   %player.setPosition( "0 0" );
   %player.objectName = "player";
}

ok, in my game.cs i have this:
function startGame(%level)
{
   exec("./player.cs");
   exec("./dataBlocks.cs");
   createPlayer();

   blah blah....
}

and in my file dataBlocks.cs i have this:
datablock t2dImageMapDatablock( playerNormal )
{
   imageName = "~/data/images/player";
   imageMode = full;
};

after that i can't see my airplane in screen, all i get is the imagemap loaded in the static sprites tab of level builder, the console doesn't show any error.

thanks in advance

#1
08/02/2006 (1:25 pm)
Apparently that's where t2dImageMapDatablocks go.

You'll want to add a static sprite to the level builder, using the Image Map Builder.
Once you have the name of that image (hover the mouse over the image to see the datablock name) you'll want to replace a line in your createPlayer() function.

This:
%player.setImageMap( playerNormal );

To This:
%player.setImageMap( [Image Map Name] );

Make sure you put the right name in the method, or it won't work.
That is how I load and apply images.
#2
08/02/2006 (1:35 pm)
Ey Kevin, i have the image in my level builder already, i want to load to the screen with scripting, the imageMap name is playerNormal
#3
08/02/2006 (9:41 pm)
If you hover the mouse over the image in TGB (in the Static Sprite section) a popup should show its name. Does it show "playerNormal" or something like "playerNormalImageMap". I think the "ImageMap" part is added automatically to all sprites you import into TGB.
#4
08/03/2006 (8:25 am)
I haven't used it so I am not sure but the definition of getSceneGraph is:

"Gets the t2dSceneGraph this object is in."

Which to me means you use it to call something like:

%scenegraph = %obj.getscenegraph();

I personally give the starting scenegraph a name like 'scenegraph1' in the editor. Then in script I store the current scenegraph in a global called $scenegraph which I load on startup:

$scenegraph = scenegraph1;

Then whenever you create a new object you can call this global:

function createPlayer()
{
   %player = new t2dStaticSprite() 
   { 
     [b]scenegraph = $scenegraph;[/b]
     class=playerPlanes;
   };
   %player.setImageMap( playerNormal );
   %player.setSize( "87 114" );
   %player.setPosition( "0 0" );
   %player.objectName = "player";
}

The other thing to keep in mind is the position of your camera. If you move your camera from it's default position (see below) your objects may be added to the world but you just can't see them because they are off screen.

-Unk
#5
08/03/2006 (8:29 am)
Set position uses world coordinates where "0 0" is whereever you defined it to be. It's the center of the level (and center of the camera) by default.
#6
08/03/2006 (8:34 am)
@Ben: Heh... my bad. =P Thanks!

-Unk
#7
09/07/2006 (8:04 am)
I was searching the forums looking for how to dynamically create sprites and put them onto the screen and there was a snippet of code in here that helped. Thanks @Rogers. I did not have the "setImageMap(...)" line. I wa relying on the datablock to supply that information. Apparently this whole time (two days) I have been drawing blank images to the scene. Frustrating.
#8
09/07/2006 (9:39 am)
@Rogers

I realize this is an old thread, but be sure to load your level BEFORE trying to add sprites. If your code above is accurate then you're basically adding the new sprite to a scenegraph of id 0 or empty.


@GC

Check your other thread, you don't need the setImageMap call at all in the code I've posted there.