为什么我的屏幕没有呈现任何内容?

时间:2016-07-20 10:22:21

标签: ios swift sprite-kit

我有以下代码。当我运行这个时,我得到一个空白屏幕。这段代码在sceneDidLoad()内,因此它们将被执行但不显示任何内容。我错过了什么吗?

let worldNode = SKNode()

let height = 100
let width = 100
let regions:[Float: String] = [-0.04: "sand", -0.08: "water", 0.9: "grass"]

let noiseSource = GKPerlinNoiseSource()
let noise: GKNoise = GKNoise(noiseSource: noiseSource)
let noiseMap: GKNoiseMap = GKNoiseMap(noise: noise)

let tileMapNode = SKTileMapNode()
tileMapNode.enableAutomapping = true
tileMapNode.numberOfRows = height
tileMapNode.numberOfColumns = width
worldNode.addChild(tileMapNode)

for y in 0 ... height {
    for x in 0 ... width {
        let currentHeight = noiseMap.value(atPosition: vector2(Int32(x), Int32(y)));

        for (key, value) in regions {
            if (currentHeight <= key) {
                //colourMap [y * mapChunkSize + x] = regions[i];
                let tileSize = CGSize(width: 32.0, height: 32.0)
                let tileTexture = SKTexture(imageNamed: value)
                let tileDef = SKTileDefinition(texture: tileTexture, size: tileSize)
                let tileGroup = SKTileGroup(tileDefinition: tileDef)

                tileMapNode.setTileGroup(tileGroup, forColumn: x, row: y)

                print("Tiling: \(value)")
                break;
            }
        }
    }
}

self.addChild(worldNode)

0 个答案:

没有答案