2D Toolkit Forum
2D Toolkit => Support => Topic started by: McSpiffy on December 10, 2014, 02:23:50 am
-
So I'm grabbing colors from from what I call a "Bitmap" not sure what the technical name is but its a png file and its not very big. Then I'm checking them against a list to see if they match. then I want to place a tile at the location that they are located on the png. So I wrote some code using for loops and foreach loops. But when I run it nothing is happen no errors I tried running a debug.log to see if it runs through the code and it seems to but nothing appears on the screen.
I'm just starting out with TK 2d so I'm still learning the basics. Any help would be appreciated. Thanks ;)
int x,y;
for( y = 0; y < shipY; y++)
{
for( x = 0; x < shipX; x++)
{
foreach(Tile t in modualeList.GetComponent<ModualeList>().tile)
{
/*
find floor layer and set all colors from the bit map to gen a random floor tile to the floor layer in the TileMap
*/
if(textureColors [x+y*shipX] == t.tileColor)
{
shipTileMap.GetComponent<tk2dTileMap>().SetTile(shipX,shipY,0,131);
}
}
}
}
shipTileMap.GetComponent<tk2dTileMap>().Build();
}
-
First - don't call GetComponent every time, its (really really really) slow and you should cache the values...
Otherwise it looks liek you're setting the tile to shipX, shipY that are constants maybe you mean x, y?
-
Wow thank you that was it. It looks so obvious now with a fresh cup of coffee in my hands >.<. I wasn't going to keep using GetComponent I just wanted to see if it would work. Thanks for the help :D