1
\$\begingroup\$

I want to create a rectangle around each tile that's blocked value = true. How can I find the X and Y (on screen) coords of the each individual Tile?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

You can calculate each tile position on screen if you know the width and height of each tile like this:

pos.x = x * tileWidth;
pos.y = y * tileHeight;

Therefore, you can go through all the tiles:

for(x = 0; x < tilemap.getWidth(); x++)
for(y = 0; y < tilemap.getHeight(); y++)
{
    if(tilemap.tiles[x][y].blocked == true){
        // This tile is blocked, get it's position on screen
        pos.x = x * tileWidth;
        pos.y = y * tileHeight;
    }
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .