Useful - Generic Functions
by Jeremy Easoz · in Torque Game Builder · 10/13/2008 (7:33 am) · 0 replies
Bored waiting on an engine compile so I thought id share a few generic tilelayer functions I created.
// Clears a Column in the TileLayer
void t2dTileLayer::clearLayerColumn(const U32 tileX, const U32 tileY)
{
if ( mppTileObjectArray )
{
// Delete All Tiles in the Column
for ( U32 n = tileX; n < (mTileCountX * mTileCountY); (n += mTileCountX) )
{
// Is there a tile here
if ( mppTileObjectArray[n] )
{
// Yes, so delete the Tile Node
mpTileMap2DManager->deleteTileNode( mppTileObjectArray[n]->mpTileNode );
// Delete the Physics.
delete mppTileObjectArray[n]->mpPhysics;
// Dele the Tile Object.
delete mppTileObjectArray[n];
// Reset the Tile Object.
mppTileObjectArray[n] = NULL;
}
}
}
}// Count Active Tiles in a TileLayer Column
U32 t2dTileLayer::countLayerColumnTiles(const U32 tileX, const U32 tileY)
{
U32 tileCount = 0;
if ( mppTileObjectArray )
{
// Count Tiles in the Tile Layer Column
for ( U32 n = tileX; n < (mTileCountX * mTileCountY); (n += mTileCountX) )
{
if ( mppTileObjectArray[n] )
{
tileCount++;
}
}
}
return ( tileCount );
}// Counts Active tiles in a TileLayer
U32 t2dTileLayer::countLayerTiles()
{
// Tile Count
U32 tileCount = 0;
// Is there an active Tile Array?
if ( mppTileObjectArray )
{
for(U32 i = 0; i < (mTileCountX * mTileCountY); i++)
{
if(mppTileObjectArray[i])
{
tileCount++;
}
}
}
return ( tileCount );
}About the author