Game Development Community

How to copy tiles between layers

by Johan Stenqvist (neochrome) · in Torque Game Builder · 06/09/2005 (5:06 am) · 2 replies

Hi!

Is there some simple way of copying tiles between two tilelayers (I wan't to merge two layers in runtime)?
Or do I have to use something like this:

function CopyTile(%srcLayer, %srcTile, %dstLayer, %dstTile)
{
	// type
	%type = %srcLayer.getTileType(%srcTile);
	switch$(getWord(%type, 0))
	{
		case "static":
			%dstLayer.setStaticTile(%dstTile, getWord(%type, 1), getWord(%type, 2));
		case "animated":
			%dstLayer.setAnimationTile(%dstTile, getWord(%type, 1));
		case "active":
			%dstLayer.setActiveTile(%dstTile, getWord(%type, 1), getWord(%type, 2));
	}
	
	// do we really have a tile??
	if(%type !$= "")
	{
		// flip
		%flip = %srcLayer.getTileFlip(%srcTile);
		%dstLayer.setTileFlip(%dstTile, getWord(%flip, 0), getWord(%flip, 1));
	
		// custom data
		%dstLayer.setTileCustomData(%dstTile, %srcLayer.getTileCustomData(%srcTile));
	
		// script
		%dstLayer.setTileScript(%dstTile, getWord(%srcLayer.getTileScript(%srcTile), 0));
		
		// collision
		%collision = %srcLayer.getTileCollision(%srcTile);
		// active?
		%dstLayer.setTileCollisionActive(%dstTile, getWord(%collision, 0));
		// scale
		%dstLayer.setTileCollisionScale(%dstTile, getWord(%collision, 1) SPC getWord(%collision, 2));
		// poly
		%edgeCount = getWord(%collision, 3);
		if(%edgeCount > 0)
		{
			%polyEdges = "";
			for(%i = 0; %i < %edgeCount; %i++)
			{
				%polyEdges = %polyEdges SPC getWord(%collision, 4 + %i * 2) SPC getWord(%collision, 5 + %i * 2);
			}
			%dstLayer.setTileCollisionPolyCustom(%dstTile, %edgeCount, %polyEdges);
		}
	}
}

#1
02/26/2006 (12:17 am)
I just did a search for "copytile" and *bam* there it was! Nice block that saved me some time, so thanks for posting this :)

I thought about doing it in C++, but there's not really a great all-purpose place to put it. The best place would probably be as a method of t2dTileMap, but of course, that would only let you copy tiles between layers on the same t2dTileMap.

Even that would be pretty useful though...
#2
02/27/2006 (12:23 am)
Glad you found some use for it. :)