简体   繁体   English

更改 SKTileMapNode 中特定图块的颜色

[英]Change color of specific tiles in SKTileMapNode

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.我正在创建一个基于圆形的游戏,其中我有一个游乐场作为 SKTileMapNode,每个瓷砖上都有草纹理,角色可以从瓷砖走到瓷砖。 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.带有纹理的 SKSpriteNode 可以简单地通过.color.colorBlendFactor改变它们的颜色,这样我的绿草纹理就会得到例如红色的触感。 How am I able to do this with specific tiles in a SKTileMapNode?我如何能够使用 SKTileMapNode 中的特定图块做到这一点?

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).一旦你有了瓷砖,你就可以修改瓷砖的纹理tile.textures以包含有色纹理或自己绘制彩色纹理(凌乱,但这里有一个例子)。

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.我会推荐一种不同的方法,虽然获得你想要着色的瓷砖中心tileMap.centerOfTile(atColumn: column, row: row)并使用它和它们的大小tileMap.tileSize在你的瓷砖上方创建节点SKSpriteNode我喜欢有色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM