how can I add a tile variant (e.g. I want a normal grass tile, then a grass tile with a flower on it, and another one with a red flower etc.) to my SKTileGroup?
here is my SKTileGroup declaration
let grass = SKTileDefinition(texture: SKTexture(imageNamed: "grass"), size: CGSize(width: 64, height: 64))
let tileGroup = SKTileGroup(tileDefinition: grass)
Apple actually has a preset file to help with this. It's called "SpriteKit Tile Set". This file allows you to fill in each possible tile orientation and have each tile follow the correct rules when used in a tile map.
As you can see, the file allows you to choose a specific type based off of what your tiles are. (Isometric like clash of clans, grid-based like enter the gungeon, or hexagonal like Civilization)
It's quite simple and intuitive. You just have to drag-n-drop each image into its corresponding slot and make sure that each image is in the Assets.xcassets folder.
The file even comes with some tile groups already in it so you can see how they function.
Each one of these is considered a tile set. A tile set contains one (or more) tile groups.
Each tile set can have as many tile groups in it as you need.
Each one of these is considered a tile group. Tile groups contain all the images that make tile sets usable in tile maps.
To access any tiles you decide to add, you need to access the tile set where the tile group is being stored. The tile set is considered an array, and can be accessed as such.
//First, we need to access the tile set where the tile groups are being stored.
let tiles = SKTileSet(named: "Sample Grid Tile Set")
let tileGroups = (tiles?.tileGroups)!
//next, we access each tile group and define them.
let grass = (tileGroups.first(where: {$0.name == "grass"}))!
let sand = tileGroups[1]
let cobblestone = tileGroups[2]
let water = tileGroups[3]
//then we collect each tile group into another tile set and put that tile set into the tile map.
let tileSet = SKTileSet(tileGroups: [water,grass,sand,cobblestone])
tileMap = SKTileMapNode(tileSet: tileSet, columns: mapWidth, rows: mapHeight, tileSize: CGSize(width: 32, height: 32))