Change color of specific tiles in SKTileMapNode

503 views Asked by At

I am creating a round based game where I have a playground as a SKTileMapNode with grass textures on every tile where characters can walk from tile to tile. Every character has his own reach where they can walk in one round. I want to display this range so that the player can see the range of the selected character. My question: How can I change the color of those tiles which are in the range of the tile where a specific character is on? SKSpriteNode with textures can simply change their color by .color and .colorBlendFactor so that my green grass texture gets for example a red touch. How am I able to do this with specific tiles in a SKTileMapNode?

1

There are 1 answers

4
Hamer On
let tile = tileMap.tileDefinition(atColumn: column, row: row)

Once you have the tile you can modify the textures of the tile tile.textures to either include tinted textures or draw the colored textures yourself (messy but here's an example of that).

I would recommend a different approach though of getting the center of the tiles tileMap.centerOfTile(atColumn: column, row: row) you'd like to color and using this and their size tileMap.tileSize to create nodes SKSpriteNode above the tiles you'd like to be colored.