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
\$\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;
    }
}
|improve this answer|||||
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.