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. 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. 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 }
-
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 }
-
▶︎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 }
-
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 }
-
▶︎speed
Set 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
width
CGFloat
object size width.height
CGFloat
object size height.type
TiledObjectShape
object 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
layer
SKObjectGroup
object 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
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.
-
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.
-
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.
-
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
currentTime
TimeInterval
update interval.
-
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 }
-
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)?)