Class

SKTileMapNode

A two-dimensional array of images.

Declaration

class SKTileMapNode : SKNode

Overview

SKTileMapNode 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.

To work with a tile map programmatically, you supply SKTileMapNode 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 setTileGroup(_:andTileDefinition:forColumn:row:).

Topics

Creating a Tile Map Programmatically

Create a tile map manually instead of loading it from an archived .sks file.

Controlling a Tile Map's On-Screen Position Relative to its Origin

var anchorPoint: CGPoint

Defines the point in the tile map that corresponds to its position.

Reading or Manually Configuring the Tile Map's Size

var tileSize: CGSize

The size of each tile in points.

var tileSet: SKTileSet

The tile set being used by this tile map. The tile map object can only display tiles that exist in this set.

var numberOfColumns: Int

The number of columns in the tile map

var numberOfRows: Int

The number of rows in the tile map.

Tinting a Tile Map

var color: UIColor

The base color for the tile map. The influence of the color over the tile map node’s textures is controlled by colorBlendFactor.

var colorBlendFactor: CGFloat

Controls the blending between the texture and the tile map object’s color. Values are clamped between zero and one where zero has no color blending and one has the maximum color blending.

Lighting a Tile Map

Configure how a sprite is lit when its near a light node.

var lightingBitMask: UInt32

A mask that defines how the tile map is lit by light nodes in the scene.

Configuring How Alpha Values Blend the Sprite

Change how a sprite uses its alpha value, such as additive blending, that results in the sprite being brighter than it was before.

var blendMode: SKBlendMode

Defines the blend mode to use when compositing the tile map over other nodes.

Working with Custom Shaders

var shader: SKShader?

Defines a shader which is applied to each tile of the tile map.

var attributeValues: [String : SKAttributeValue]

The values of each attribute associated with the node's attached shader.

func setValue(SKAttributeValue, forAttribute: String)

Sets an attribute value for an attached shader.

See Also

Tiling

class SKTileDefinition

A single tile that can be repeated in a tile map.

class SKTileGroup

A set of tiles that collectively define one type of terrain.

class SKTileGroupRule

Rules that describe how various tiles should be placed in a map.

class SKTileSet

A container for related tile groups.