SKTilesetDataSource
public protocol SKTilesetDataSource : AnyObject
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
}
}
-
▶︎willAddSpriteSheet(to:
Default implementationfileNamed: ) Provide an image name for the tileset before textures are generated.
Default Implementation
Called when a tileset is about to render a spritesheet.
Declaration
Swift
func willAddSpriteSheet(to tileset: SKTileset, fileNamed: String) -> String
Parameters
to
SKTileset
tileset instance.fileNamed
String
spritesheet name.Return Value
String
spritesheet name. -
▶︎willAddImage(to:
Default implementationforId: fileNamed: ) Provide an alernate image name for an image in a collection.
Default Implementation
Called when a tileset is about to add an image from a collection.
Declaration
Swift
func willAddImage(to tileset: SKTileset, forId: Int, fileNamed: String) -> String
Parameters
to
SKTileset
tileset instance.forId
Int
tile id.fileNamed
String
image name.Return Value
String
image name.