我一直在牆上撞擊我的頭幾個小時。我正嘗試使用CIFilter修改我的應用程序中的紋理,然後將該新紋理作爲新SKTileDefinition的一部分在我的地圖上重新着色。 函數波紋管發現玩家「擁有」的圖塊,並嘗試通過將SKTileDefinition更改爲coloredDefinition
來重新着色。以編程方式創建一個SKTileDefinition
func updateMapTileColoration(for players: Array<Player>){
for player in players {
for row in 0..<mainBoardMap!.numberOfRows {
for col in 0..<mainBoardMap!.numberOfColumns {
let rowReal = mainBoardMap!.numberOfRows - 1 - row
if player.crownLocations!.contains(CGPoint(x: row, y: col)) {
if let tile = mainBoardMap!.tileDefinition(atColumn: col, row: rowReal) {
let coloredDefinition = colorizeTile(tile: tile, into: player.color!)
print(coloredDefinition.name)
mainBoardMap!.tileSet.tileGroups[4].rules[0].tileDefinitions.append(coloredDefinition)
mainBoardMap!.setTileGroup(crownGroup!, andTileDefinition: crownGroup!.rules[0].tileDefinitions[1], forColumn: col, row: rowReal)
}
}
}
}
}
這裏是actulaly應用CIFilter功能:colorizeTile
func colorizeTile(tile: SKTileDefinition, into color: UIColor) -> SKTileDefinition{
let texture = tile.textures[0]
let colorationFilter = CIFilter(name: "CIColorMonochrome")
colorationFilter!.setValue(CIImage(cgImage: texture.cgImage()), forKey: kCIInputImageKey)
colorationFilter!.setValue(CIColor(cgColor: color.cgColor), forKey: "inputColor")
colorationFilter!.setValue(0.25, forKey: "inputIntensity")
let coloredTexture = texture.applying(colorationFilter!)
let newDefinition = SKTileDefinition(texture: texture)
newDefinition.textures[0] = coloredTexture
newDefinition.name = "meow"
return newDefinition
}
我很想搞清楚爲什麼像我試圖做我不能改變tileDefinition任何幫助。看起來直觀上正確的是,能夠定義一個新的TileDefinition並將其添加到tileGroup,然後將該tile組設置爲特定的tile定義。但是,這導致瓷磚空白...
任何指針?