Home > Enterprise >  What is the proper way to create an SKTileSet and SKTileMapNode?
What is the proper way to create an SKTileSet and SKTileMapNode?

Time:05-28

This is what I have:

class GameScene: SKScene {
    let tileSet = SKTileSet?(named: "Hexes")
    let map = SKTileMapNode(tileSet: tileSet, columns: 10, rows: 10, tileSize: .init(width: 20, height: 20))
}

According to the developer documentation this is corrects far as I can see, but I am getting the error: 'Extraneous argument label 'named:' in call'.

If I remove (named: "Hexes"), then I get: 'Expected member name or constructor call after type name', and the second line has multiple errors as well.

Thanks in advance.

CodePudding user response:

let tileSet = SKTileSet?(named: "Hexes")

The ? is not wanted there - you are calling a failable initializer which is one that returns an optional SKTileSet.init(named:) returns an optional SKTileSet, but you don't call it with a ?

let tileSet = SKTileSet(named: "Hexes")

If you want to make the type explicit, you would write it like:

let tileSet: SKTileSet? = SKTileSet(named: "Hexes")
  • Related