Paint tiles on a map by putting tile definitions in a group that you create in code.
To paint tiles on a map using a tile group, you call
fill on the group. The fill behaviors you use depend on the type of group you make:
Repeats the single center tile.
Multiple tiles without adjacency rules
Chooses randomly among the multiple center tiles, abiding by the placement weights you choose.
Multiple tiles with adjacency rules
Repeats the center tile and borders all of its edges using the peripheral adjacency tiles you define.
Create a Tile Group with a Single Tile
Although a tile group is a container for multiple tiles, you can create one with a single tile, if you wish. Use the
init initializer, as shown in the following code.
Create a Heterogenous Tile Group with Random Placement
For a tile group with more than one texture, use the
init initializer. The following code shows how you can create a tile group containing two definitions—one based on an image named
RED and the other on an image named
When a tile map node is supplied with a tile set using this group and its tiles are filled with the
fill method, the placement weights control the random assignment of tiles. In this case, there are three times more red than blue tiles.
Create a Tile Group Using Adjacency Rules
To create a tile group that uses adjacency, you need to create a set of rules for each of the adjacency values. For a grid-based layout, you need 13 rules, as shown in the following illustration:
To create the tile group programmatically, create definitions and rules for each adjacency:
The 13 rules are used to make a tile group:
With automapping enabled, when an individual tile is placed on the map using
set, SpriteKit also sets the tile definitions for the surrounding tiles based on the group's adjacency rules.