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
See moreProperty Description none Object is a simple vector object type. text Object is text object. tile Object is effectively a tile. Declaration
Swift
public enum TiledObjectType : Stringextension SKTileObject.TiledObjectType: CustomStringConvertible, CustomDebugStringConvertible -
Overview
Describes a vector object shape.
Properties
See moreProperty Description rectangle Rectangular object shape. ellipse Circular object shape. polygon Closed polygonal object shape. polyline Open polygonal object shape. Declaration
Swift
public enum TiledObjectShape : Stringextension SKTileObject.TiledObjectShape: CustomStringConvertible, CustomDebugStringConvertible -
▶︎layerObject parent layer.
Declaration
Swift
weak open var layer: SKObjectGroup! -
▶︎uuidUnique id (layer & object names may not be unique).
Declaration
Swift
open var uuid: String -
▶︎idTiled object id.
Declaration
Swift
open var id: Int -
▶︎typeObject type.
Declaration
Swift
open var type: String! -
▶︎sizeObject 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 } -
▶︎tileDataTile data (for tile objects).
Declaration
Swift
open var tileData: SKTilesetData? { get } -
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 -
Custom object properties.
Declaration
Swift
open var properties: [String : String] -
Ignore custom properties.
Declaration
Swift
open var ignoreProperties: Bool -
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 } -
▶︎textText string (for text objects). Setting this attribute will redraw the object automatically.
Declaration
Swift
open var text: String! { get set } -
▶︎boundsReturns the bounding box of the shape.
Declaration
Swift
open var bounds: 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 } -
▶︎speedSet the object speed value.
Declaration
Swift
override open var speed: CGFloat { get set }
-
Initialize the object with width & height attributes.
Declaration
Swift
required public init(width: CGFloat, height: CGFloat, type: TiledObjectShape = .rectangle)Parameters
widthCGFloatobject size width.heightCGFloatobject size height.typeTiledObjectShapeobject shape type. -
Initialize the object attributes dictionary.
Declaration
Swift
required public init?(attributes: [String : String])Parameters
attributes[String: String]object attributes. -
Initialize the object with an object group reference.
Declaration
Swift
required public init(layer: SKObjectGroup)Parameters
layerSKObjectGroupobject group.
-
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
colorSKColorfill & stroke color.alphaCGFloatalpha 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
colorhexStringhex color string.alphaCGFloatalpha component for fill.
-
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
withScaleCGFloatrender quality scaling.Return Value
CGImagerendered text image.
-
Returns the internal
SKTileObject.pointsarray, translated into the current map’s projection.Declaration
Swift
public func getVertices() -> [CGPoint]?Return Value
[CGPoint]?array of points.
-
Show/hide the object’s boundary shape.
Declaration
Swift
open var showBounds: Bool { get set }
-
Setup physics for the object based on properties set up in Tiled.
Declaration
Swift
open func setupPhysics()
-
Update the object before each frame is rendered.
Declaration
Swift
open func update(_ deltaTime: TimeInterval)Parameters
currentTimeTimeIntervalupdate interval.
-
Object description.
Declaration
Swift
override open var description: String { get } -
▶︎opacityObject opacity
Declaration
Swift
open var opacity: CGFloat { get set } -
▶︎visibleObject 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 }
-
Runs tile animation.
Declaration
Swift
@available(*, deprecated) open func runAnimation()
-
Parse the object’s properties value.
Declaration
Swift
public func parseProperties(completion: (() -> Void)?)
View on GitHub
SKTileObject Class Reference