Here is my code:
/
import AppKit
import GameKit
import PlaygroundSupport
let frame = CGRect(x:0, y:0, width: 300, height: 300)
let view = SKView(frame: frame)
PlaygroundPage.current.liveView = view
class LakeScene : SKScene {
override func didMove(to view: SKView) {
super.didMove(to: view)
guard let tileSet = SKTileSet(named: "Sample Grid Tile Set") else {
fatalError("Tile Set not found")
}
let tileSize = CGSize(width: 128.0, height: 128.0)
let tileMap = SKTileMapNode(tileSet: tileSet, columns: 1, rows: 1, tileSize: tileSize)
guard let waterTileGroup = tileSet.tileGroups.first(where: {$0.name == "Water"}) else {
fatalError("Tile Group not found")}
tileMap.fill(with: waterTileGroup)
addChild(tileMap)
}
}
let scene = LakeScene()
view.presentScene(scene)
I am using the example Tile Set that you get when you make a SpriteKit Tile Set file. I make the file then drag it and the Assets.xcassets into my Playground's Resources folder.
Here is a screenshot: