Class

SKTileMapNode

A node used to render a 2D array of textured sprites.

Declaration

class SKTileMapNode : SKNode

Overview

You supply an SKTileMapNode a tile set which defines the tile definitions it can render. You can fill each tile in the tile map with the fill(with:) method and explicitly set the definitions for individual tiles with the setTileGroup(_:andTileDefinition:forColumn:row:) method.

You can layer individual tile maps with different blend modes and, since they are SpriteKit nodes, they can be controlled by actions and physics allowing, for example, parallax scrolling. The rendered tile map can be post processed with an SKShader to add effects such as motion blur or atmospheric perspective.

An SKTileMapNode can only render tile definitions that exist within the SKTileSet you have provided it.

Topics

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.

Initializers

init(tileSet: SKTileSet, columns: Int, rows: Int, tileSize: CGSize)

Creates and initializes a tile map node using the provided tile set with a specified number of columns and rows. For a grid set type, the overall size in points of the node will be numberOfColumns * tileSize.width wide and numberOfRows * tileSize.height high. This initializer creates an empty tile map.

init(tileSet: SKTileSet, columns: Int, rows: Int, tileSize: CGSize, fillWith: SKTileGroup)

Creates and initializes a tile map node using the provided tile set with a specified number of columns and rows. For a grid set type, the overall size, in points, of the node will be numberOfColumns * tileSize.width wide and numberOfRows * tileSize.height high. This initializer fills each tile with a texture defined by the descriptors in the final SKTileGroup argument.

init(tileSet: SKTileSet, columns: Int, rows: Int, tileSize: CGSize, tileGroupLayout: [SKTileGroup])

Creates and initializes a tile map node using the provided tile set with a specified number of columns and rows. For a grid set type, the overall size, in points, of the node will be numberOfColumns * tileSize.width wide and numberOfRows * tileSize.height high.

Instance Properties

var anchorPoint: CGPoint

Defines the point in the sprite that corresponds to the node’s position.

var blendMode: SKBlendMode

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

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.

var enableAutomapping: Bool

Specifies whether the tile map object should attempt to resolve the group and definition of neighboring tiles set by setTileGroup(_:forColumn:row:).

var lightingBitMask: UInt32

A mask that defines how this sprite is lit by light nodes in the scenes.

var mapSize: CGSize

The overall size of the tile map.

var numberOfColumns: Int

The number of columns in the tile map

var numberOfRows: Int

The number of rows in the tile map.

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 tileSize: CGSize

The size of each tile in points.

Instance Methods

func fill(with: SKTileGroup?)

Fills each tile in a tile map node object with a tile group.

func setTileGroup(SKTileGroup, andTileDefinition: SKTileDefinition, forColumn: Int, row: Int)

Set the tile group and tile definition at the specified tile index. When auto-mapping is enabled, it will attempt to resolve the surrounding tiles to allow the specified tile definition to be placed. When auto-mapping is disabled, it will simply place the tile definition and not modify any of the neighboring tiles.

func setTileGroup(SKTileGroup?, forColumn: Int, row: Int)

Set the tile group at the specified tile index. When auto-mapping is enabled, the appropriate tile definitions will automatically be selected and placed, possibly modifying neighboring tiles. When auto-mapping is disabled, it will simply place the default center tile definition for the group, and will not modify any of the neighboring tiles.

func tileRowIndex(fromPosition: CGPoint) -> Int

Returns the tile map node object’s tile row index for the specified position in points.

See Also

Building Content with Tiles

class SKTileDefinition

A class that describes a single type of tile that is used within a tile map.

class SKTileGroupRule

A class that defines how tiles should be placed in a map.

class SKTileGroup

A class that encapsulates a collection of related tile definitions that are designed to be pieced together within a tile map.

class SKTileSet

A class that contains all the tile definitions available for use in a tile map.