SKTileObject

open class SKTileObject : SKShapeNode, SKTiledObject

Overview

The SKTileObject class represents a Tiled vector object type (rectangle, ellipse, polygon & polyline). When the object is created, points can be added either with an array of CGPoint objects, 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

Property Description
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.
  • Overview

    Describes the object type (tile object, text object, etc).

    Properties

    Property Description
    none Object is a simple vector object type.
    text Object is text object.
    tile Object is effectively a tile.
    See more

    Declaration

    Swift

    public enum TiledObjectType : String
    extension SKTileObject.TiledObjectType: CustomStringConvertible, CustomDebugStringConvertible
  • Overview

    Describes a vector object shape.

    Properties

    Property Description
    rectangle Rectangular object shape.
    ellipse Circular object shape.
    polygon Closed polygonal object shape.
    polyline Open polygonal object shape.
    See more

    Declaration

    Swift

    public enum TiledObjectShape : String
    extension SKTileObject.TiledObjectShape: CustomStringConvertible, CustomDebugStringConvertible
  • ▶︎layer

    Object parent layer.

    Declaration

    Swift

    weak open var layer: SKObjectGroup!
  • ▶︎uuid

    Unique id (layer & object names may not be unique).

    Declaration

    Swift

    open var uuid: String
  • ▶︎id

    Tiled object id.

    Declaration

    Swift

    open var id: Int
  • ▶︎type

    Object type.

    Declaration

    Swift

    open var type: String!
  • ▶︎size

    Object size.

    Declaration

    Swift

    open var size: CGSize
  • Object is visible in camera.

    Declaration

    Swift

    open var visibleToCamera: Bool
  • Enable tile animation.

    Declaration

    Swift

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

    Tile data (for tile objects).

    Declaration

    Swift

    open var tileData: SKTilesetData? { get }
  • ▶︎frameColor

    Object bounds color.

    Declaration

    Swift

    open var frameColor: SKColor
  • Overview

    Describes tile vector object collision type.

    Properties

    Property Description
    none No physics collisions.
    dynamic Object is a dynamic physics body.
    collision Object records collisions only.

    Declaration

    Swift

    public enum CollisionType
  • ▶︎properties

    Custom object properties.

    Declaration

    Swift

    open var properties: [String : String]
  • Ignore custom properties.

    Declaration

    Swift

    open var ignoreProperties: Bool
  • ▶︎physicsType

    Physics collision type.

    Declaration

    Swift

    open var physicsType: CollisionType
  • Invert hysics properties.

    Declaration

    Swift

    open var invertPhysics: Bool
  • Text formatting attributes (for text objects).

    Declaration

    Swift

    open var textAttributes: TextObjectAttributes!
  • Text object render quality.

    Declaration

    Swift

    open var renderQuality: CGFloat { get set }
  • ▶︎text

    Text string (for text objects). Setting this attribute will redraw the object automatically.

    Declaration

    Swift

    open var text: String! { get set }
  • ▶︎bounds

    Returns the bounding box of the shape.

    Declaration

    Swift

    open var bounds: CGRect { get }
  • ▶︎anchorPoint

    Returns the object anchor point (based on the current map’s tile size).

    Declaration

    Swift

    open var anchorPoint: CGPoint { get }
  • Signifies that this object is a text or tile object.

    Declaration

    Swift

    open var isRenderableType: Bool { get }
  • ▶︎isPolyType

    Signifies that this object is a polygonal type.

    Declaration

    Swift

    open var isPolyType: Bool { get }
  • ▶︎speed

    Set the object speed value.

    Declaration

    Swift

    override open var speed: CGFloat { get set }

Init

Drawing

  • 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

    SKColor fill & stroke color.

    alpha

    CGFloat alpha component for fill.

  • 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

    color

    hexString hex color string.

    alpha

    CGFloat alpha component for fill.

Rendering

  • ▶︎draw(debug:)

    Render the object.

    Declaration

    Swift

    open func draw(debug: Bool = false)
  • 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

    CGFloat render quality scaling.

    Return Value

    CGImage rendered text image.

Geometry

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

    Declaration

    Swift

    public func getVertices() -> [CGPoint]?

    Return Value

    [CGPoint]? array of points.

Debugging

  • ▶︎showBounds

    Show/hide the object’s boundary shape.

    Declaration

    Swift

    open var showBounds: Bool { get set }

Dynamics

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

    Declaration

    Swift

    open func setupPhysics()

Updating

  • ▶︎update(_:)

    Update the object before each frame is rendered.

    Declaration

    Swift

    open func update(_ deltaTime: TimeInterval)

    Parameters

    currentTime

    TimeInterval update interval.

Extensions

  • ▶︎description

    Object description.

    Declaration

    Swift

    override open var description: String { get }
  • ▶︎opacity

    Object opacity

    Declaration

    Swift

    open var opacity: CGFloat { get set }
  • ▶︎visible

    Object visibility

    Declaration

    Swift

    open var visible: Bool { get set }
  • ▶︎isAnimated

    Returns true if the object references an animated tile.

    Declaration

    Swift

    open var isAnimated: Bool { get }
  • ▶︎isTextObject

    Signifies that the object is a text object.

    Declaration

    Swift

    open var isTextObject: Bool { get }
  • ▶︎isTileObject

    Signifies that the object is a tile object.

    Declaration

    Swift

    open var isTileObject: Bool { get }

Deprecated

Generic Properties