TiledEventHandler

@objc
public protocol TiledEventHandler

The TiledEventHandler protocol delegates optional handlers for mouse (macOS) and touch (iOS) events.

Instance Methods

  • mouseOverTileHandler: Custom tile mouse over event handler. macOS
  • mouseOverObjectHandler: Custom object mouse over event handler. macOS
  • tileClickedHandler: Custom tile mouse click event handler. macOS
  • objectClickedHandler: Custom object mouse click event handler. macOS
  • tileTouchedHandler: Custom tile touch event handler. iOS
  • objectTouchedHandler: Custom object touch event handler. iOS

Usage

Mouse & Touch Handlers

The optional delegate method mouseOverTileHandler allows mouse and touch event handlers to be added to tiles and vector objects:

@objc public func mouseOverTileHandler(globalID: UInt32, ofType: String?) -> ((SKTile) -> ())? {
    guard let tileType = ofType else {
        return nil
    }

    switch tileType {
        case "floors":
            return { (tile) in tile.tileData.setValue(for: "color", "#308CC6") }

        case "walls":
            return { (tile) in tile.tileData.setValue(for: "color", "#8E6214") }

        default:
            return nil
    }
}

The tileClickedHandler allows you to set a custom click handler for tiles & objects:

@objc func tileClickedHandler(globalID: UInt32, ofType: String?, button: UInt8) -> ((SKTile) -> ())? {
    switch globalID {
        case 24, 25:
            return { (tile) in
                tile.tileData.setValue(for: "wasVisited", "true")
        }
        default:
            return nil
    }
}
  • Custom handler for tiles at creation time.

    Declaration

    Swift

    @objc
    optional func onCreate(globalID: UInt32, ofType: String?) -> ((SKTile) -> ())?

    Parameters

    globalID

    tile global id.

    ofType

    optional tile type.

  • Custom mouse over handler for objects matching the given type (macOS only).

    Declaration

    Swift

    @objc
    optional func onCreate(ofType: String?) -> ((SKTileObject) -> ())?

    Parameters

    ofType

    optional object type.

  • Custom mouse over handler for tiles matching the given properties (macOS only).

    Declaration

    Swift

    @objc
    optional func mouseOverTileHandler(globalID: UInt32, ofType: String?) -> ((SKTile) -> ())?

    Parameters

    globalID

    tile global id.

    ofType

    optional tile type.

  • Custom mouse click handler for tiles matching the given properties (macOS only).

    Declaration

    Swift

    @objc
    optional func tileClickedHandler(globalID: UInt32, ofType: String?, button: UInt8) -> ((SKTile) -> ())?

    Parameters

    clicks

    number of mouse clicks required.

    globalID

    tile global id.

    ofType

    optional tile type.

    button

    mouse button.

  • Custom mouse over handler for objects matching the given properties (macOS only).

    Declaration

    Swift

    @objc
    optional func mouseOverObjectHandler(withID: UInt32, ofType: String?) -> ((SKTileObject) -> ())?

    Parameters

    withID

    object id.

    ofType

    optional object type.

  • Custom mouse click handler for objects matching the given properties (macOS only).

    Declaration

    Swift

    @objc
    optional func objectClickedHandler(withID: UInt32, ofType: String?, button: UInt8) -> ((SKTileObject) -> ())?

    Parameters

    withID

    object id.

    ofType

    optional object type.

    button

    mouse button.

  • Custom touch handler for tiles matching the given properties (iOS only).

  • Custom touch handler for objects matching the given properties (iOS only).

  • Custom handler for when the SKTilemap.currentCoordinate value changes. The resulting closure contains a tuple of values:

    • old: old coordinate.
    • new: new coordinate.
    • isValid: coordinate is a valid map coordinate.

    Declaration

    Swift

    @objc
    optional var coordinateChangeHandler: ((simd_int2, simd_int2, Bool) -> ())? { get set }

    Return Value

    coordinate change handler.