Different shaped tilemaps
by zackl · in Torque Game Builder · 08/03/2010 (4:33 pm) · 7 replies
Hi I am new to TGB and new to programming in general. I was wondering how you could make different shaped tilemaps. I am going through the match3 tutorial and wanted to make different shaped levels. How would I do this. I have looked throught the forums and havn't seen anything. I have been through most of the tutorials and havn't seen anything that I could see that would be useful.I've put background tile images in the tile editor and just wanted the tiles that you swap to only be placed over these. Sorry if I am unclear. I would appreciate any help.
thank you
thank you
#2
if(%this.t2dTileLayer.customData = 1)
{
...
}
or would I be looking for something else.
Again thank you for your time.
and if you need any 3d or 2d work done let me know.
08/04/2010 (6:20 am)
Hey thanks for the reply. I have tried to set the custom data field to different names but when I select the other tiles(the ones I don't want to have a tile on) the custom data field stays the same for both.Also would I put an if statement likeif(%this.t2dTileLayer.customData = 1)
{
...
}
or would I be looking for something else.
Again thank you for your time.
and if you need any 3d or 2d work done let me know.
#3
Specifically you want to look at the lines like:
The first sets the custom data for the tile at <%x,%y> to be "0". The second gets the custom data at the tile <%x,%y>.
08/04/2010 (8:25 am)
You should look at an example that Patrick wrote. It's not exactly what you need, but you'll see examples of the custom data being set and retreieved there.Specifically you want to look at the lines like:
%this.setTileCustomData( %x, %y, 0 ); %var = %this.getTileCustomData( %x, %y);
The first sets the custom data for the tile at <%x,%y> to be "0". The second gets the custom data at the tile <%x,%y>.
#4
08/04/2010 (8:53 am)
Do you set the custom data in the editor? 0r just cycle through and find the tiles I have set up with a background image in script?I hope I am not bugging you with these n00b questions it is just a different train of thought than what I am used to.
#5
When I run this I get:
t2dTileLayer::setTileCustomData() - Empty Tile Position! (6, 2)
does the (6,2) refer to 6 tiles over(x) and 2 down(y) or is it based on pixels
08/04/2010 (9:32 am)
Ok I have started over (just more practice right)When I run this I get:
t2dTileLayer::setTileCustomData() - Empty Tile Position! (6, 2)
does the (6,2) refer to 6 tiles over(x) and 2 down(y) or is it based on pixels
function Board::onLevelLoaded(%this,%scenegraph)
{
$board = %this;
$board.xCount = $board.getTileCountX();
$board.yCount = $board.getTileCountY();
$PiecesInPlay = new SimSet();
$board.createBoard();
}
function Board::createBoard(%this)
{
for(%x = 0;%x < $board.xCount;%x++)
{
for(%y = 0;%y < $board.yCount;%y++)
{
if($board.t2dTileLayer.imageMap $= "btileImageMap")
{
%this.setTileCustomData(%x,%y,1);
}
else
{
%this.setTileCustomData(%x,%y,0);
}
}
}
}
#6
08/04/2010 (9:42 am)
I figured it out...I have blank tiles filling the spaces that I don't want tiles and I forgot to add that one.
#7
All I basically did was look for the custom data and if it was zero I deleted the pieces here check it out.
thanks for all your help It is definately appreciated.
08/05/2010 (3:30 am)
Hey i think I got it. I just don't know if this solution will cause problems with the match and swap mechanics.Could you look and see if this is right or close to.All I basically did was look for the custom data and if it was zero I deleted the pieces here check it out.
function Board::onLevelLoaded(%this,%scenegraph)
{
$board = %this;
$board.xCount = $board.getTileCountX();
$board.yCount = $board.getTileCountY();
$PiecesInPlay = new SimSet();
for(%a = 0;%a < $board.xCount;%a++)
{
for(%b = 0;%b < $board.yCount;%b++)
{
$board.pieces[%a,%b] = new t2dStaticSprite()
{
scenegraph = %this.getSceneGraph();
class = "tile";
layer = "10";
};
$board.pieces[%a,%b].setSize(5,5);
%color = tileRandomColor();
$board.pieces[%a,%b].imageMap = ("tile" @ %color @ "ImageMap");
//%back = $board.grid[%a,%b].getTilecustomData(%a,%b);
$PiecesInPlay.add($board.pieces[%a,%b]);
//set the position of the piece relative to the tile layer (grid) we made
$board.pieces[%a,%b].setPosition(getTileGridPosition(%a,%b));
if ($board.getTileCustomData(%a,%b) == 0)
{
$board.pieces[%a,%b].delete();
}
}
}
$PiecesInPlay.getCount();
echo($PiecesInPlay.getCount());
}
function getTileGridPosition(%x,%y)
{
//grab the Board layer's position
%tileMapPos = $board.getPosition();
//divide the position up into x and y variables
%tileMapPosX = getWord(%tileMapPos,0);
%tileMapPosY = getWord(%tileMapPos,1);
//grab the Board layer's size
%tileMapSize = $board.getSize();
//Divide the size up into X and Y variables
%tileMapSizeX = getWord(%tileMapSize,0);
%tileMapSizeY = getWord(%tileMapSize,1);
//calculate the start position
%tileMapStartX = %tileMapPosX - (%tileMapSizeX / 2);
%tileMapStartY = %tileMapPosY - (%tileMapSizeY / 2);
//currently size set to 6,6
%ts = $board.getTileSize();
//calculate the position and pass it back
%pos = (%tileMapStartX + (%x * %ts)) + %ts/2 SPC (%tileMapStartY + (%y * %ts)) + %ts/2;
return %pos;
}
function tileRandomColor()
{
%color = getRandom(1,6);
return %color;
}thanks for all your help It is definately appreciated.
Associate William Lee Sims
Machine Code Games
What I would do next is to iterate over all of the tiles looking for ones with the tile set to your background image. For those that are set, you can add some custom data to the tile. Then, you'll probably need to modify the match3 code to only check those tiles that have the custom data set.
The custom data is easy. Just set it to "1" for tiles that have your background image and to "0" for those that don't. Then make sure your match3 code only checks tiles with "1" set for their custom data.
Good luck!