Hello Guest

Author Topic: Hi I'm have trouble generating my tile map from code.  (Read 3190 times)

McSpiffy

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Hi I'm have trouble generating my tile map from code.
« 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  ;)

Code: [Select]
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();
}

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Hi I'm have trouble generating my tile map from code.
« Reply #1 on: December 10, 2014, 09:36:23 am »
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?

McSpiffy

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Hi I'm have trouble generating my tile map from code.
« Reply #2 on: December 10, 2014, 04:31:09 pm »
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
« Last Edit: December 10, 2014, 04:40:28 pm by McSpiffy »