Globals

SKTiled globals are accessible via the TiledGlobals object. This structure enables the user to set default values for various API objects, as well as enable/disable debugging functions.

// Access the default `TiledGlobals` singleton
let globals = TiledGlobals.default

Aliases

  • The TiledGlobals object provides information about the framework, as well as allowing you to set default attributes for various objects.

    Properties

    • renderer: returns the current SpriteKit renderer (get-only).
    • loggingLevel: global logging verbosity.
    • updateMode: default tile update mode.
    • enableRenderCallbacks: enable callbacks from the tilemap on rendering statistics.
    • enableCameraCallbacks: enable callbacks from camera to camera delegates.
    • renderQuality: global render quality values.
    • contentScale: returns the device retina display scale factor.
    • version: returns the current framework version.

    Usage

    SKTiled framework default values are set in the TiledGlobals object.

    // access the default singleton instance
    let tiledGlobals = TiledGlobals.default
    
    // disable camera callbacks
    tiledGlobals.enableCameraCallbacks = false
    
    // set debugging mouse filters (macOS)
    tiledGlobals.debugDisplayOptions.mouseFilters = [.tileCoordinates, .tilesUnderCursor]
    
    // increase the default text object render quality
    tiledGlobals.renderQuality.text = 12.0
    
    See more

    Declaration

    Swift

    public class TiledGlobals
  • The DebugDrawOptions structure represents debug drawing options for SKTiled objects.

    Usage

    // show the map's grid & bounds shape
    tilemap.debugDrawOptions = [.drawGrid, .drawFrame]
    
    // turn off layer grid visibility
    layer.debugDrawOptions.remove(.drawGrid)
    

    Properties

    • drawGrid: visualize the nodes’s tile grid.
    • drawFrame: visualize the nodes’s bounding rect.
    • drawGraph: visualize the nodes’s pathfinding graph.
    • drawObjectFrames: draw object’s bounding shapes.
    • drawAnchor: draw the layer’s anchor point.
    See more

    Declaration

    Swift

    public struct DebugDrawOptions : OptionSet
  • The CameraZoomClamping enumeration denotes the camera zoom rounding factor. Clamps the zoom value to the nearest whole pixel value in order to alleviate cracks appearing in between individual tiles.

    Properties

    • none: do not clamp camera zoom.
    • half: clamp zoom to the nearest half-pixel.
    • third: clamp zoom to the nearest third of a pixel.
    • quarter: clamp zoom to the nearest quarter of a pixel.
    • tenth: clamp zoom to the nearest 1/10 of a pixel.
    See more

    Declaration

    Swift

    public enum CameraZoomClamping : CGFloat
  • The TileRenderMode flag determines how a particular tile instance is rendered. If the default is specified, the tile renders however the parent tilemap tells it to. Only set this flag to override a particular tile instance’s render behavior.

    Properties

    • default: Tile renders at default settings.
    • static: Tile ignores any animation data.
    • ignore: Tile does not take into account its tile data.
    • animated: Animate with a global id value.

    Declaration

    Swift

    public enum TileRenderMode
  • The TileUpdateMode enumeration dictates how the tilemap updates its tiles in your scene. Changing this property can drastically affect your CPU usage, so use it carefully.

    The default mode is TileUpdateMode.actions, which should be used for the best performance. In this mode, animated tiles are animated with SpriteKit actions.

    If full mode is used, each tile (animated or otherwise) is updated every frame. This ensures accuracy in syncronizing frames.

    Important

    If dynamic or full mode is selected, the SKTilemap node must be included in your scene’s main update loop to render properly.

    Usage

    // passing the tile update mode to the load function
    if let tilemap = SKTilemap.load(tmxFile: "MyFile.tmx", updateMode: TileUpdateMode.dynamic) {
        scene.addChild(tilemap)
    }
    
    // updating the attribute on the tilemp node
    tilemap.updateMode = TileUpdateMode.actions
    

    Properties

    • dynamic: dynamically update tiles as needed.
    • full: all tiles are updated each frame.
    • actions: tiles are not updated, SpriteKit actions are used instead.
    See more

    Declaration

    Swift

    public enum TileUpdateMode : UInt8
  • The TextObjectAttributes structure is used for managing basic font rendering attributes for text objects.

    Properties

    • fontName: font name.
    • fontSize: font size.
    • fontColor: font color.
    • alignment: horizontal/vertical text alignment.
    • wrap: text wraps.
    • isBold: text is bold.
    • isItalic: text is italicized.
    • isUnderline: text is underlined.
    • renderQuality: font scaling attribute.
    See more

    Declaration

    Swift

    public struct TextObjectAttributes