Protocols

SKTiled protocols represent blueprints of requirements (methods, properties) to allow users to interact with Tiled content.

  • Overview

    The SKTiledObject protocol defines a basic data structure for mapping custom Tiled properties to SpriteKit objects. Objects conforming to this protocol will automatically receive properties from the Tiled scene, unless supressed by setting the object’s SKTiledObject.ignoreProperties property.

    Properties

    Property Description
    uuid Unique object id.
    type Tiled object type.
    properties Object of custom Tiled properties.
    ignoreProperties Ignore Tiled properties.
    renderQuality Resolution multiplier value.

    Instance Methods

    Method Description
    parseProperties Parse function (with optional completion block).

    Usage

    // query a Tiled string property
    if let name = tiledObject.stringForKey("name") {
       tiledObject.name = name
    }
    
    // query a boolean property
    let isDynamic = tiledObject.boolForKey("isDynamic") == true
    
    See more

    Declaration

    Swift

    @objc
    public protocol SKTiledObject
  • Overview

    Methods that allow interaction with an SKTilemap object as it is being created to customize its properties.

    Properties

    Property Description
    zDeltaForLayers Default z-distance between layers.

    Instance Methods

    Delegate callbacks are called asynchronously as the map is being read from disk and rendered:

    Method Description
    didBeginParsing Called when the tilemap is instantiated.
    didAddTileset Called when a tileset is added to a map.
    didAddLayer Called when a layer is added to a tilemap.
    didReadMap Called when the tilemap is finished parsing.
    didRenderMap Called when the tilemap layers are finished rendering.
    didAddNavigationGraph Called when the a navigation graph is built for a layer.
    objectForTileType Specify a custom tile object for use in tile layers.
    objectForVectorType Specify a custom object for use in object groups.
    objectForGraphType Specify a custom graph node object for use in navigation graphs.

    Custom Objects

    Custom object methods can be used to substitute your own objects for tiles:

    func objectForTileType(named: String? = nil) -> SKTile.Type {
        if (named == "MyTile") {
           return MyTile.self
        }
       return SKTile.self
    }
    
    See more

    Declaration

    Swift

    public protocol SKTilemapDelegate : AnyObject
  • Overview

    Methods for managing SKTilemap nodes in an SpriteKit SKScene scene. This protocol and the SKTiledScene objects are included as a suggested way to use the SKTilemap class, but are not required.

    In this configuration, the tile map is a child of the root node and reference the custom SKTiledSceneCamera camera.

    SKTiledSceneDelegate Overview

    Properties

    Property Description
    worldNode Root container node. Tiled assets are parented to this node.
    cameraNode Custom scene camera.
    tilemap Tile map node.

    Instance Methods

    Method Description
    load(tmxFile:) Load a tilemap from disk.
    See more

    Declaration

    Swift

    public protocol SKTiledSceneDelegate : AnyObject
  • Overview

    Methods for interacting with the custom SKTiledSceneCamera. Classes conforming to this protocol are notified of camera position & zoom changes - unless the SKTiledSceneCameraDelegate.receiveCameraUpdates flag is disabled.

    Tiled Scene Camera Delegate

    Properties

    Method Description
    receiveCameraUpdates Delegate will receive camera updates.

    Instance Methods

    Method Description
    containedNodesChanged Called when the nodes in the camera view changes.
    cameraPositionChanged Called when the camera positon changes.
    cameraZoomChanged Called when the camera zoom changes.
    cameraBoundsChanged Called when the camera bounds updated.
    sceneDoubleClicked Called when the scene is double-clicked. (macOS only)
    mousePositionChanged Called when the mouse moves in the scene. (macOS only)
    sceneDoubleTapped Called when the scene is double-tapped. (iOS only)
    See more

    Declaration

    Swift

    @objc
    public protocol SKTiledSceneCameraDelegate
  • Overview

    Methods which allow the user to dynamically alter the properties of a tileset as it is being created.

    Instance Methods

    Delegate callbacks are called asynchronously as the tileset is being rendered.

    Method Description
    willAddSpriteSheet Provide an image name for the tileset before textures are generated.
    willAddImage Provide an alernate image name for an image in a collection.

    Usage

    Implementing the SKTilesetDataSource.willAddSpriteSheet method allows the user to specify different spritesheet images. Take care that these images have the same dimensions & layout.

    extension MyScene: SKTilesetDataSource {
        func willAddSpriteSheet(to tileset: SKTileset, fileNamed: String) -> String {
            if (currentSeason == .winter) {
                return "winter-tiles-16x16.png"
            }
            if (currentSeason == .summer) {
                return "summer-tiles-16x16.png"
            }
            return fileNamed
        }
    }
    
    See more

    Declaration

    Swift

    public protocol SKTilesetDataSource : AnyObject