Game Development Community

creating tileMaps

by David Deschenes · in Torque Game Builder · 07/14/2009 (2:43 pm) · 1 replies

i just have a quick question, when creating a tileMap from script, what are the needed fields? can it even be created like this?




%map = new t2dTileMap()
{
tileCount = %length SPC %height;
tileSize = "0 0";
position = "0 0";
name = map;

};

#1
07/15/2009 (7:49 am)
David,

NOTE: I replied to your email as well.

The t2dTileMap is nothing more than a parent object that aggregates the tile-layers. This can be confusing but in the original designed I required the ability to load/save tile-layers into/from a single file. I also needed the ability to share internal animation and active-tile structures over several related tile-layers.

All the tile-map does is act like an owning factory for tile-layers. It doesn't render and it doesn't need to specify tile-counts and sizes. Indeed, those fields and methods don't exist on it.

If you have created a tile-map and assigned it to the scene-graph you're ready to create tile-layers. You create tile-layers by using:
%tileLayer = %tileMap.createTileLayer( %tileCountX, %tileCountY, %tileSizeX, %tileSizeY );
%tileLayer.setSize( ... );
%tileLayer.setPosition( ... );
%tileLayer.setRotation( ... );
etc...
The tile-layer is a scene-object which does render and can be mounted, positioned, rotated etc.

If you delete the tile-map which "owns" it then all the tile-layers you created wil be destroyed as well. Alternately you can use:
%tileMap.removeTileLayer( %tileLayer );
When setting the position/size of the tile-layer, the choice is obviously yours but the tile-layer won't scale-down/up the tiles themselves, they'll always be drawn at the original tile-size specified when you created the tile-layer (see above). You can turn-on wrapping so that if you pan the tile-layer (inside its size window) then it'll either wrap the tiles or not.

Assuming a pan of (0,0) to set the size of the tile-layer so that all the tiles will show (assuming it fits inside the current camera view) then you set the size to be:

%tileLayer.setSize( %tileCountX * %tileSizeX, %tileCountY * %tileSizeY );
The grid (and most other settings) apply to the tile-layers themselves as individual objects, NOT the tile-map so (for instance), turning on the tile-grid is done against the specific tile-layer you want to show it on so:
%tileLayer.setGridActive();
In your example above, you were setting the "tileCount" and "tileSize" on the tile-map which doesn't make sense, it doesn't have any tiles, just tile-LAYERS. Also, you were setting the tile-grid on the tile-map but this should be on the respective tile-layer.

Hopefully there are no errors here, I've not used v1.7.4 for a while and lots of things have changed since that release.

Hope this ellaboration helps.

Melv.