Game Development Community

Setting a class for a tile map in script

by Gregory Ray · in Torque Game Builder · 08/24/2008 (2:11 pm) · 2 replies

In tgb i can build a tilemap and set the class in edit and scripting but if i create a tilemap via script how do I set the class so it can inherit the same functions that my tilemaps i create in game builder have?

this is my code for creating the tile map

function newTile(){
%map = new t2dTileMap() {scenegraph = myScene;};
%map.createTileLayer("2 1", "2 2");
%newBlock = %map.getTileLayer(0);
%newBlock.setStaticTile("0 0", ally_orangeImageMap);
%newBlock.setStaticTile("1 0", ally_orangeImageMap);
%newBlock.setPosition( "14 10" );
//%newBlock.class = Block;
shapeGroup.add(%newBlock);
}

#1
08/24/2008 (2:52 pm)
Don't allocate a t2dTileMap in script, because im pretty sure it won't work. There is only one tilemap which you can get with t2dscenegraph::getglobaltilemap.

What I think you are really asking is how to create a new t2dTileLayer. Even so, I had a lot of problems trying to do this. As I recall it did not like t2dTileLayers without a layerFile so I was trying something like this...

%newLayer = new t2dTileLayer()
{
   LayerFile = "game/data/tilemaps/templatelayer.lyr";
};
    
sceneWindow2D.getSceneGraph().getGlobalTileMap().addTileLayer(%newLayer);
%newLayer.loadTileLayer(%newLayer.layerFile);
%newLayer.setSize("20 20");  // or something
%newLayer.setPosition("0 0"); // or something

If you can create your tilelayers in advance in the editor and just assign their tiles dynamically from script I would recommend it, or you can experiment with this idea.
#2
08/24/2008 (3:00 pm)
Oh and to answer your other question, you would assign the class name to the class field when you create the object.

%newLayer = new t2dTileLayer()
{
class = "TileLayerClass";
};