TilesetDataSource

public protocol TilesetDataSource : AnyObject

The TilesetDataSource protocol outlines 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.

  • 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 TilesetDataSource.willAddSpriteSheet method allows the user to specify different spritesheet images. Take care that these images have the same dimensions & layout.

extension MyScene: TilesetDataSource {
    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
    }
}
  • willAddSpriteSheet(to:fileNamed:) Default implementation

    Provide an image name for the tileset before textures are generated. Implement this method to allow custom sprite sheet images to be loaded.

    Default Implementation

    Called when a tileset is about to process a spritesheet image. This method allows you to substitute a new filename before the tileset is built.

    Declaration

    Swift

    func willAddSpriteSheet(to tileset: SKTileset, fileNamed: String) -> String

    Parameters

    tileset

    Tileset instance.

    fileNamed

    Spritesheet name.

    Return Value

    Spritesheet name.

  • willAddImage(to:forId:fileNamed:) Default implementation

    Provide an alernate image name for an image in a collection tileset. Implement this method to allow remapping of images before the tileset is created.

    Default Implementation

    Called when a tileset is about to add an image from a collection. This method allows you to substitute a new filename before the tileset is built.

    Declaration

    Swift

    func willAddImage(to tileset: SKTileset, forId: UInt32, fileNamed: String) -> String

    Parameters

    tileset

    Tileset instance.

    forId

    Tile id.

    fileNamed

    Image name.

    Return Value

    Image name.