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
TiledObjectTypeenumeration describes a vector object type (tile object, text object, etc).Properties
Declaration
Swift
public enum TiledObjectType : String -
The
TiledObjectTypeenumeration 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 -
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
-
Indicates the current node has received focus or selected.
Declaration
Swift
public var isFocused: Bool { get set } -
Declaration
Swift
@objc public var _debugLevel: UInt8 -
Debug visualization options.
Declaration
Swift
public var debugDrawOptions: DebugDrawOptions -
Object is visible in camera.
Declaration
Swift
open var visibleToCamera: Bool -
This object’s
CGPathdefining the shape of geometry. Used to draw the bounding shape.Declaration
Swift
@objc public lazy var objectPath: CGPath { get set } -
Enable tile animation.
Declaration
Swift
open var enableAnimation: Bool { get set } -
Object tile (for tile objects).
Declaration
Swift
public internal(set) var tile: SKTile? { get } -
Signifies that the object has been fully initialized.
Declaration
Swift
open internal(set) var isInitialized: Bool { get } -
Number of times this object has been redrawn (debug).
Declaration
Swift
open var drawCount: UInt32 -
Tile data (for tile objects).
Declaration
Swift
open var tileData: SKTilesetData? { get }
-
Object bounds color.
Declaration
Swift
open var frameColor: SKColor -
Object highlight color.
Declaration
Swift
open var highlightColor: SKColor -
Optional proxy color.
Declaration
Swift
open var proxyColor: SKColor? -
Optional tint color.
Declaration
Swift
open var tintColor: SKColor? { get set }
-
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
CollisionTypeenumeration 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
-
Custom object properties.
Declaration
Swift
open var properties: [String : String] -
Object will ignore custom properties.
Declaration
Swift
open var ignoreProperties: Bool -
Physics collision type.
Declaration
Swift
open var physicsType: CollisionType -
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 string (for text objects). Setting this attribute will redraw the object automatically.
Declaration
Swift
open var text: String! { get set } -
Returns the bounding box of the shape.
Declaration
Swift
open override var boundingRect: CGRect { get } -
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 } -
Signifies that this object is a polygonal type.
Declaration
Swift
open var isPolyType: Bool { get }
-
Initialize the object with width & height attributes.
Declaration
Swift
required public init(width: CGFloat, height: CGFloat, type: TiledObjectShape = .rectangle)Parameters
widthobject size width.
heightobject size height.
typeobject 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
attributesattributes 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
layerobject group.
-
Instantiate the node with a decoder instance.
Declaration
Swift
required public init?(coder aDecoder: NSCoder)Parameters
aDecoderdecoder.
-
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
colorfill & stroke color.
alphaalpha component for fill.
redrawforce 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
hexStringhex color string.
alphaalpha component for fill.
redrawforce object to redraw.
-
Set the tile object’s tile data.
Declaration
Swift
open func setTileData(_ data: SKTilesetData)Parameters
datatile data instance.
-
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
withScalerender quality scaling.
Return Value
rendered text image.
-
Returns the internal
SKTileObject.pointsarray, 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) -> BoolParameters
touchtouch point in this node.
Return Value
node was touched.
-
Object has begun rendering.
Declaration
Swift
open func didBeginRendering(completion: (() -> Void)? = nil)Parameters
completionoptional completion handler.
-
Object has finished rendering.
Declaration
Swift
open func didFinishRendering(completion: (() -> Void)? = nil)Parameters
completionoptional completion handler.
-
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.
-
Update the object before each frame is rendered.
Declaration
Swift
open func update(_ deltaTime: TimeInterval)Parameters
deltaTimeupdate interval.
-
Returns a custom mirror for this object.
Declaration
Swift
public var customMirror: Mirror { get }
-
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
colorhighlight color.
durationduration of highlight effect.
-
Remove the current object’s highlight color.
Declaration
Swift
@objc public override func removeHighlight()
-
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
debugdebug draw option.
-
Returns a shortened textual representation for debugging.
Declaration
Swift
@available(*, deprecated, renamed: "tiledListDescription") open var shortDescription: String { get }
-
Parse the object’s properties.
Declaration
Swift
public func parseProperties(completion: (() -> Void)?)Parameters
completionoptional completion closure.
View on GitHub
Install in Dash
SKTileObject Class Reference