SKTile

open class SKTile : SKSpriteNode

Overview

The SKTile class is a custom SpriteKit sprite node that references its data from a tileset.

Tile data (including texture) is stored in SKTilesetData property.

Properties

Property Description
tileSize tile size (in pixels)
tileData tile data structure
layer parent tile layer

Instance Methods

Method Description
setupPhysics(shapeOf:isDynamic:) Setup physics for the tile.
setupPhysics(rectSize:isDynamic:) Setup physics for the tile.
setupPhysics(withSize:isDynamic:) Setup physics for the tile.
runAnimation() Play tile animation (if animated).
removeAnimation(restore:) Remove animation.
runAnimationAsActions() Runs a SpriteKit action to animate tile tile (if animated).
removeAnimationActions(restore:) Remove the animation for the current tile.
  • ▶︎tileSize

    Tile size.

    Declaration

    Swift

    open var tileSize: CGSize
  • ▶︎tileData

    Tileset tile data.

    Declaration

    Swift

    open var tileData: SKTilesetData
  • ▶︎layer

    Weak reference to the parent layer.

    Declaration

    Swift

    weak open var layer: SKTileLayer!
  • Object is visible in camera.

    Declaration

    Swift

    open var visibleToCamera: Bool
  • ▶︎renderMode

    Render mode for this instance.

    Declaration

    Swift

    open var renderMode: TileRenderMode { get set }
  • ▶︎isTileObject

    Returns true if the tile is part of a tile object.

    Declaration

    Swift

    public internal(set) var isTileObject: Bool { get }
  • Overview

    Alignment hint used to define how to handle tile positioning within layers & objects (in the event the tile size is different than the parent).

    Properties

    Property Description
    topLeft Tile is positioned at the upper left.
    top Tile is positioned at top.
    topRight Tile is positioned at the upper right.
    left Tile is positioned at the left.
    center Tile is positioned in the center.
    right Tile is positioned to the right.
    bottomLeft Tile is positioned at the bottom left.
    bottom Tile is positioned at the bottom.
    bottomRight Tile is positioned at the bottom right.
    See more

    Declaration

    Swift

    public enum TileAlignmentHint : Int
    extension SKTile.TileAlignmentHint: CustomStringConvertible, CustomDebugStringConvertible
  • Tile highlight color.

    Declaration

    Swift

    open var highlightColor: SKColor
  • ▶︎frameColor

    Tile bounds color.

    Declaration

    Swift

    open var frameColor: SKColor
  • Tile highlight duration.

    Declaration

    Swift

    open var highlightDuration: TimeInterval
  • Enable tile animation.

    Declaration

    Swift

    open var enableAnimation: Bool { get set }
  • ▶︎PhysicsShape

    Overview:

    Describes the tile’s physics shape.

    Properties

    Property Description
    none No physics shape.
    rectangle Rectangular object shape.
    ellipse Circular object shape.
    texture Texture-based shape.
    path Open path.
    See more

    Declaration

    Swift

    public enum PhysicsShape
    extension SKTile.PhysicsShape: CustomStringConvertible, CustomDebugStringConvertible
  • ▶︎physicsShape

    Physics body shape.

    Declaration

    Swift

    open var physicsShape: PhysicsShape
  • ▶︎bounds

    Returns the bounding box of the shape.

    Declaration

    Swift

    open var bounds: CGRect { get }

Init

  • ▶︎init(data:)

    Initialize the tile object with SKTilesetData.

    Declaration

    Swift

    required public init?(data: SKTilesetData)

    Parameters

    data

    SKTilesetData tile data.

    Return Value

    SKTile tile sprite.

  • ▶︎init(coder:)

    Default initializer.

    Declaration

    Swift

    required public init?(coder aDecoder: NSCoder)

    Parameters

    aDecoder

    decoder instance.

  • ▶︎init()

    Initialize an empty tile.

    Declaration

    Swift

    required public init()
  • Initialize the tile with a tile size.

    Declaration

    Swift

    public init(tileSize size: CGSize)

    Parameters

    tileSize

    CGSize tile size in pixels.

    Return Value

    SKTile tile sprite.

  • Initialize the tile texture.

    Declaration

    Swift

    public init(texture: SKTexture?)

    Parameters

    texture

    SKTexture? tile texture.

    Return Value

    SKTile tile sprite.

  • ▶︎draw(debug:)

    Draw the tile. Force the tile to update its textures.

    Declaration

    Swift

    open func draw(debug: Bool = false)

    Parameters

    debug

    Bool debug draw.

Physics

  • Set up the tile’s dynamics body.

    Declaration

    Swift

    open func setupPhysics(shapeOf: PhysicsShape = PhysicsShape.rectangle, isDynamic: Bool = false)

    Parameters

    shapeOf

    PhysicsShape tile physics shape type.

    isDynamic

    Bool physics body is active.

  • Set up the tile’s dynamics body with a rectanglular shape.

    Declaration

    Swift

    open func setupPhysics(rectSize: CGSize, isDynamic: Bool = false)

    Parameters

    rectSize

    CGSize rectangle size.

    isDynamic

    Bool physics body is active.

  • Set up the tile’s dynamics body with a rectanglular shape.

    Declaration

    Swift

    open func setupPhysics(withSize: CGFloat, isDynamic: Bool = false)

    Parameters

    withSize

    CGFloat rectangle size.

    isDynamic

    Bool physics body is active.

  • Set up the tile’s dynamics body with a circular shape.

    Declaration

    Swift

    open func setupPhysics(radius: CGFloat, isDynamic: Bool = false)

    Parameters

    radius

    CGFloat circle radius.

    isDynamic

    Bool physics body is active.

  • Remove tile physics body.

    Declaration

    Swift

    open func removePhysics()

    Parameters

    withSize

    CGFloat dynamics body size.

Animation

Legacy Animation

Overlap

  • Set the tile overlap amount.

    Declaration

    Swift

    open func setTileOverlap(_ overlap: CGFloat)

    Parameters

    overlap

    CGFloat overlap amount.

Geometry

  • Returns the points of the tile’s shape.

    Declaration

    Swift

    open func getVertices(offset: CGPoint = CGPoint.zero) -> [CGPoint]

    Return Value

    [CGPoint]? array of points.

Updating

  • ▶︎update(_:)

    Render the tile before each frame is rendered.

    Declaration

    Swift

    open func update(_ deltaTime: TimeInterval)

    Parameters

    deltaTime

    TimeInterval update interval.

Extensions

Deprecated

  • Pauses tile animation

    Declaration

    Swift

    @available(*, deprecated, message: "Use the default `SKNode.isPaused` to pause animation.")
    open var pauseAnimation: Bool { get set }