A two-dimensional array of images.
SDKs
- iOS 10.0+
- macOS 10.12+
- Mac Catalyst 13.0+
- tvOS 10.0+
- watchOS 3.0+
Framework
- Sprite
Kit
Declaration
class SKTileMapNode : SKNode
Overview
SKTile
does the work of laying out predefined tiles in a grid of any size. Typically, you configure 9-slice images (tile groups) in Xcode's SpriteKit scene editor and paint the look of your tile map ahead of time versus configuring the tile map in code.
As with sprite nodes, you can layer tile maps with different blend modes or control it with actions and physics, for example, for the purpose of parallax scrolling. The rendered tile map can be post processed with an SKShader
to add effects such as motion blur or atmospheric perspective.
Note
A tile map can only render tile definitions that exist within the SKTile
you have provided it.
Important
A tile map does not expose its tiles as nodes, and therefore you cannot assign individual tiles with a different z
or physics
. Instead, layer tile map nodes on top of each other at the varying zPositions, and layer invisible SKNodes
on top of the tile map node to attach physicsBodies to your tile map node.
To work with a tile map programmatically, you supply SKTile
with a tile set that defines the tile definitions it can render. Then, fill each tile in the tile map with the fill(with:)
method and set individual tiles with set
.