Game Development Community

Properly aligning tile layers?

by Christopher Gu · in Torque Game Builder · 11/30/2005 (11:15 am) · 4 replies

Is there a way to properly align a tilemap once it's loaded so that the first tile seen on the screen is the leftmost tile in my tilemap? Right now when I load a layer it seems to start scrolling somewhere towards the middle of the layer. Ive been getting around this by marking my tiles with numbers and then moving them around by calling setPosition(). This gets pretty tedious though, especially since my tilemaps have upwards of 21 layers and I sometimes get offsets in the thousands.

Also, as a side note, will the tile editor in torque 1.1 allow for more than 21 layers? Right now it seems to be limited by the amount of layers that one can fit on the pulldown bar, which seems unnecessarily restrictive.

#1
11/30/2005 (12:03 pm)
You could use this:
%backLayerTileCountX=GetWord(%backLayer.getTileCount(),0);   
%backLayerTileSizeX=GetWord(%backLayer.getTileSize(),0);   
%currentCameraviewWidth=GetWord(sceneWindow2D.getCurrentCameraArea(),2);   
%backLayerStartPosX=(((%backLayerTileCountX * %backLayerTileSizeX) / 2) - %currentCameraviewWidth /2);   
%backLayer.setPosition( %backLayerStartPosX SPC "0" );
It gets the horizontal width of the map, the tiles and the camera view and then positions the layer accordingly.
#2
12/01/2005 (2:57 am)
@Christopher: You can use Page Up/Down to select your tile-layers. Ultimately, the menu is only going to be able to display so many.

I'm a little confused about your question here. You're asking about the scroll position but then you mention "setPosition()". If you want to set the area that the tile-layer occupies, then use...
%tileLayer.setArea( <someArea> );
... or if you want your tiles to occupy the current camera view then use...
%tileLayer.setArea( myWindow.getCurrentCameraArea() );

If you want to reset the scroll-position so that tile (0,0) is at the top-left then simply use...
%tileLayer.setPanPosition( "0 0" );

Right now, the tile-editor only resets a few properties of the tile-layers before it saves them after all, the tile-editor isn't anything special, it's just another script application doing all the stuff you can do so certain attributes need resetting. Right now, to have the pan-position reset, I'd need to add the above command directly preceeding the "saveMap" and "saveLayer" functions in the tile-editor ("editorScreen.cs"). I'll have a look at adding that in the SDK.

21 Layers, wow. ;)

- Melv.
#3
12/01/2005 (3:05 am)
Okay, I just had a quick look and what I said above still stands *but* I just remembered that I decided to write the tile-editor so that the camera moved rather than adjusting the pan-position so it should be set to "0 0" by default and shouldn't be changed. This means that your pan positions should be reset so something else is going on there for you.

Maybe it's me getting confused over what you mean; perhaps just using "setArea()" which is a core-call, will solve your issue.

- Melv.
#4
12/01/2005 (8:01 am)
OMG! I just realised that in the alpha#1, set/get current/target camera area returns "x y w h" instead of the new "x1 y1 x2 y2" that all other calls use. I'll change this immediately so be careful when using the "getCurrentCameraArea()" example above.

"setArea()" is still the way to go though.

The "t2dSceneWindow::getCurrentCameraArea()" has been replaced with...
//-----------------------------------------------------------------------------
// Get Current Camera Area.
//-----------------------------------------------------------------------------
ConsoleMethod(t2dSceneWindow, getCurrentCameraArea, const char*, 2, 2, "Get current camera Area.")
{
    // Fetch Camera Window.
    const RectF cameraWindow = object->getCurrentCameraArea();

    // Create Returnable Buffer.
    char* pBuffer = Con::getReturnBuffer(64);
    // Format Buffer.
    dSprintf(pBuffer, 64, "%f %f %f %f", cameraWindow.point.x, cameraWindow.point.y, cameraWindow.point.x+cameraWindow.extent.x-1, cameraWindow.point.y+cameraWindow.extent.y-1);
    // Return Buffer.
    return pBuffer;
}

- Melv.