SKTileObject

open class SKTileObject : SKShapeNode, CustomReflectable, TiledObjectType

The SKTileObject class represents a Tiled vector object type (rectangle, ellipse, polygon, point & polyline). When the object is created, points can be added either with an array of points, or a string. In order to render the object, the SKTileObject.getVertices() method is called, which returns the points needed to draw the path.

Properties

  • id: Tiled object id.
  • size: object size.
  • tileData: tile data (for tile objects).
  • text: text string (for text objects). Setting this redraws the object.
  • bounds: returns the bounding box of the shape.

For more information, see the Working with Objects page in the [official documentation][sktiled-docroot-url].

  • The TiledObjectType enumeration describes a vector object type (tile object, text object, etc).

    Properties

    • none: object is a simple vector object type.
    • text: object is text object.
    • tile: object is effectively a tile.
    • point: object is a references a single point.

    Declaration

    Swift

    public enum TiledObjectType : String
  • The TiledObjectType enumeration describes the shape of vector objects.

    Properties

    • rectangle: rectangular object shape.
    • ellipse: circular object shape.
    • polygon: closed polygonal object shape.
    • polyline: ppen polygonal object shape.

    Declaration

    Swift

    public enum TiledObjectShape : String
  • Object parent layer.

    Declaration

    Swift

    open weak var layer: SKObjectGroup!
  • Unique id (layer & object names may not be unique).

    Declaration

    Swift

    open var uuid: String
  • id

    Tiled object id.

    Declaration

    Swift

    open var id: UInt32
  • Object type.

    Declaration

    Swift

    open var type: String!
  • Object size.

    Declaration

    Swift

    open var size: CGSize

Move Up

Color Attributes

Shape Attributes

  • Object bounding shape.

    Declaration

    Swift

    @objc
    public lazy var boundsShape: SKShapeNode? { get set }
  • Object anchor node visualization node.

    Declaration

    Swift

    @objc
    public lazy var anchorShape: SKShapeNode { get set }
  • The CollisionType enumeration describes tile vector object collision type.

    Properties

    • none: no physics collisions.
    • dynamic: object is a dynamic physics body.
    • collision: object records collisions only.

    Declaration

    Swift

    public enum CollisionType

Properties

Initialization

  • Initialize the object with width & height attributes.

    Declaration

    Swift

    required public init(width: CGFloat,
                         height: CGFloat,
                         type: TiledObjectShape = .rectangle)

    Parameters

    width

    object size width.

    height

    object size height.

    type

    object shape type.

  • Initialize the object with a dictionary of object attributes from the Tiled source XML.

    Declaration

    Swift

    required public init?(attributes: [String : String])

    Parameters

    attributes

    attributes parsed from Tiled XML.

  • Removes this node from the scene graph.

    Declaration

    Swift

    open override func destroy()
  • Initialize the object with an object group reference.

    Declaration

    Swift

    required public init(layer: SKObjectGroup)

    Parameters

    layer

    object group.

  • Instantiate the node with a decoder instance.

    Declaration

    Swift

    required public init?(coder aDecoder: NSCoder)

    Parameters

    aDecoder

    decoder.

Colors

  • Set the fill & stroke colors (with optional alpha component for the fill).

    Declaration

    Swift

    open func setColor(color: SKColor,
                       withAlpha alpha: CGFloat = 0.35,
                       redraw: Bool = true)

    Parameters

    color

    fill & stroke color.

    alpha

    alpha component for fill.

    redraw

    force object to redraw.

  • Set the fill & stroke colors with a hexadecimal string.

    Declaration

    Swift

    open func setColor(hexString: String,
                       withAlpha alpha: CGFloat = 0.35,
                       redraw: Bool = true)

    Parameters

    hexString

    hex color string.

    alpha

    alpha component for fill.

    redraw

    force object to redraw.

Tile Data

Rendering

  • Render the object.

    Declaration

    Swift

    @objc
    open func draw()
  • Draw the text object. Scale factor is to allow for text to render clearly at higher zoom levels.

    Declaration

    Swift

    open func drawTextObject(withScale: CGFloat = 8) -> CGImage?

    Parameters

    withScale

    render quality scaling.

    Return Value

    rendered text image.

Geometry

  • Returns the internal SKTileObject.points array, translated into the current map’s projection.

    Declaration

    Swift

    @objc
    public override func getVertices(offset: CGPoint = CGPoint.zero) -> [CGPoint]

    Return Value

    array of points.

  • Returns true if the touch event (mouse or touch) hits this node.

    Declaration

    Swift

    @objc
    public override func contains(touch: CGPoint) -> Bool

    Parameters

    touch

    touch point in this node.

    Return Value

    node was touched.

Events & Handlers

Callbacks

Dynamics

  • Setup physics for the object based on properties set up in Tiled.

    Declaration

    Swift

    open func setupPhysics()
  • Returns a path representing the physics shape.

    Declaration

    Swift

    open func getPhysicsPath() -> CGPath?

    Return Value

    path object.

Updating

  • Update the object before each frame is rendered.

    Declaration

    Swift

    open func update(_ deltaTime: TimeInterval)

    Parameters

    deltaTime

    update interval.

Reflection

Extensions

  • Reference to the objects’s parent tilemap.

    Declaration

    Swift

    open var tilemap: SKTilemap? { get }
  • Object opacity.

    Declaration

    Swift

    open var opacity: CGFloat { get set }
  • Object visibility.

    Declaration

    Swift

    open var visible: Bool { get set }
  • Returns true if the object references an animated tile.

    Declaration

    Swift

    open var isAnimated: Bool { get }
  • Signifies that the object is a text object.

    Declaration

    Swift

    open var isTextObject: Bool { get }
  • Signifies that the object is a tile object.

    Declaration

    Swift

    open var isTileObject: Bool { get }
  • Highlight the tile with a given color & duration.

    Declaration

    Swift

    @objc
    public override func highlightNode(with color: SKColor, duration: TimeInterval = 0)

    Parameters

    color

    highlight color.

    duration

    duration of highlight effect.

  • Remove the current object’s highlight color.

    Declaration

    Swift

    @objc
    public override func removeHighlight()

Deprecations

  • gid

    Tiled global id (for tile objects).

    Declaration

    Swift

    @available(*, deprecated, renamed: "globalID")
    open var gid: UInt32! { get set }
  • Tiled global id (for tile objects).

    Declaration

    Swift

    @available(*, deprecated, renamed: "maskedTileId")
    public var realTileId: UInt32 { get }
  • Runs a tile animation.

    Declaration

    Swift

    @available(*, deprecated)
    open func runAnimation()
  • Draw the object.

    Declaration

    Swift

    @available(*, deprecated, renamed: "draw(﹚")
    open func draw(debug: Bool = false)

    Parameters

    debug

    debug draw option.

  • Returns a shortened textual representation for debugging.

    Declaration

    Swift

    @available(*, deprecated, renamed: "tiledListDescription")
    open var shortDescription: String { get }

SKTileObject