Game Development Community

Basic tutorial background tile map

by Nathan Gordon · in Torque Game Builder · 10/24/2005 (9:56 pm) · 3 replies

I just recently purchased the t2d license and have been doing the basic tutorial. It was going really quick and easy until I tried to add the scrolling tile map to the background. I can get it to display but I cant get it to take up the entire window. There is a small strip at the top and a larger strip at the bottom where i can see the torque 2d default background image sticking out from behind the sky tile map. Does anyone know what maybe causing this? I tried to take the official code from the developers site and run it with that, but it had the exact same problem.

function CreateTileMap()
{
// Create tile-map.
%scrollerMap = new fxTileMap2D() { scenegraph = t2dSceneGraph; };

// Load saved tile-map file.
%scrollerMap.loadTileMap("~/client/maps/scroller.map");

// Load tile layer from tile-map
%skyLayer = %scrollerMap.getTileLayer( 0 );

// Generate Scrolling sky, re-size to fill the whole screen
%skyLayer.setPosition( "0 -10" );
%skyLayer.setTileSize( "25 25" );
%skyLayer.setWrap( true, false );
%skyLayer.setAutoPan( "10 0" );

}

#1
10/25/2005 (1:18 am)
I had the excact same problem, so I added

%skyLayer.setSize("100 75");

and it worked well.

- Levin
#2
10/25/2005 (1:35 am)
Unfortunately, when I through this together, I thought I'd reduce the overdraw by not extending the sky to the bottom of the screen because it's overdrawn by mountains anyway. In reality, it makes very little difference and has cause LOTS of confusion and has therefore been talked about endlessly on the forums. I accept the beating I'm due. ;)

Anyway, in the next release, there's a special tutorial background that is used to bypass this confusion.

If you want it to fill the screen and keep the tile aspect ratios the same then just make the tile sizes bigger. Also, you need to set the tile-layer object size which is the window to which these tiles render, irrelevant of the tile-sizes themselves.

Something like:

%skyLayer.setPosition( "0 0" ); // Center of screen.
%skyLayer.setSize("100 75"); // Whole screen.
%skyLayer.setTileSize( "25 25" ); // Each tile size.


For your information, the next release makes stuff like this much easier which the ability to make a call "%obj.setArea()" to tell any object to fill a specific area of the world rather than having to specify position/size.

Sorry for any confusion.

- Melv.
#3
10/25/2005 (6:39 am)
That worked perfectly thanks a lot.