Class

SKTileMapNode

A two-dimensional array of images.

Declaration

@interface 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 fillWithTileGroup: 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

anchorPoint

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

Reading or Manually Configuring the Tile Map's Size

tileSize

The size of each tile in points.

tileSet

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

numberOfColumns

The number of columns in the tile map

numberOfRows

The number of rows in the tile map.

Querying the Tile Map's Properties

- tileRowIndexFromPosition:

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

mapSize

The overall size of the tile map.

Tinting a Tile Map

color

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

colorBlendFactor

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.

lightingBitMask

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.

blendMode

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

Working with Custom Shaders

shader

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

attributeValues

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

- setValue:forAttributeNamed:

Sets an attribute value for an attached shader.

- valueForAttributeNamed:

The value of a shader attribute.

Relationships

Inherits From

See Also

Tiling

SKTileDefinition

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

SKTileGroup

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

SKTileGroupRule

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

SKTileSet

A container for related tile groups.