TiledObjectType
@objc
public protocol TiledObjectType : TiledCustomReflectableType
The TiledObjectType protocol defines a basic node type with a data structure for mapping custom Tiled
properties to SpriteKit nodes. The TiledObjectType.parseProperties method maps Tiled node custom properties to SpriteKit/SKTiled properties.
Objects conforming to this protocol will automatically receive properties from the source Tiled scene, unless supressed by setting the nodes’s TiledObjectType.ignoreProperties property.
Properties
uuid: unique object id.type: Tiled object type.properties: object of custom Tiled properties.ignoreProperties: ignore Tiled properties.parseProperties: parse Tiled attributes (with optional completion handler).
Usage
Querying a property is simple. Simply use the hasKey function:
tiledObject.hasKey("floorColor")
If a property value is convertible to other types (such as boolean, integer or double), you can use one of several convenience methods to query the value:
// query a Tiled integer property
let score = tiledObject.intForKey("scoreValue") ?? 0
// query a TIled boolean property
let isDynamic = tiledObject.boolForKey("isDynamic") == true
Finally, you can subscript the properties dictionary with any object conforming to the TiledObjectType protocol:
// use a subscript to query a property or add a new one
let floorColor = tiledObject["floorColor"]
tiledObject["orientation"] = "bottom-left"
For more information, see the Tiled Properties page in the official documentation. Also see the Tiled Properties page in the Tiled Documentation.
-
Unique object id (layer & object names may not be unique).
Declaration
Swift
@objc var uuid: String { get } -
Object type property as parsed from the Tiled scene.
Declaration
Swift
@objc var type: String! { get set } -
Storage for custom Tiled properties. These properties are set in the Tiled scene.
Declaration
Swift
@objc var properties: [String : String] { get set } -
Ignore custom node properties.
Declaration
Swift
@objc var ignoreProperties: Bool { get set } -
Parse function (with optional completion block).
Declaration
Swift
@objc optional func parseProperties(completion: (() -> Void)?)
-
mirrorChildren()Extension methodReturns a mirror representation of the properties attribute.
Declaration
Swift
public func mirrorChildren() -> [(label: String, value: Any)]Return Value
array of mirror child values.
-
getValue(for:Extension methoddefaultValue: ) Query and return a custom property. Optionally setting a default value.
Declaration
Swift
public func getValue(for key: String, defaultValue: String? = nil) -> String?Parameters
keyproperty key.
defaultdefault value, if the property doesn’t already exist.
Return Value
custom property value.
-
setValue(for:Extension method_: ) Sets a named
SKTiledproperty.Declaration
Swift
public func setValue(for key: String, _ value: String)Parameters
keyproperty key.
valueproperty value.
-
subscript(_:Extension method) Return a string value for the given key, if it exists.
Usage
if let name = tileData["name"] { print("tile data is named '\(name)'") }Declaration
Swift
public subscript(key: String) -> String? { get set }Parameters
keyStringkey to query. -
hasPropertiesExtension methodReturns true if the node has stored properties.
Declaration
Swift
public var hasProperties: Bool { get } -
propertiesStringExtension methodReturns a string representation of the node’s properties.
Declaration
Swift
public var propertiesString: String { get } -
propertiesAttributedString(delineator:Extension method) Returns an attributed string representation of the node’s properties.
Declaration
Swift
public func propertiesAttributedString(delineator: String?) -> NSAttributedStringParameters
delineatorparam string delineator.
Return Value
attributed string.
-
hasKey(_:Extension method) Returns true if the node has the given custom
SKTiledproperty (case insensitive).Declaration
Swift
public func hasKey(_ key: String) -> BoolParameters
keycustom property key.
-
boolForKey(_:Extension method) Returns a boolean value for the given key.
Declaration
Swift
public func boolForKey(_ key: String) -> BoolParameters
keyproperty key.
-
stringForKey(_:Extension method) Returns a string for the given SKTiled key.
Declaration
Swift
public func stringForKey(_ key: String) -> String?Parameters
keyproperty key.
-
intForKey(_:Extension method) Returns a integer value for the given key.
Declaration
Swift
public func intForKey(_ key: String) -> Int?Parameters
keyproperty key.
-
unsignedIntForKey(_:Extension method) Returns an unsigned integer value for the given key.
Declaration
Swift
public func unsignedIntForKey(_ key: String) -> UInt?Parameters
keyproperty key.
-
doubleForKey(_:Extension method) Returns a float value for the given key.
Declaration
Swift
public func doubleForKey(_ key: String) -> Double?Parameters
keyproperty key.
Return Value
parsed double value.
-
colorForKey(_:Extension method) Returns a color given a property string.
Declaration
Swift
public func colorForKey(_ key: String) -> SKColor?Parameters
keyproperty key.
Return Value
parsed color.
-
removeValue(for:Extension method) Remove a named SKTiled property, returns the value as a string (if property exists).
Declaration
Swift
public func removeValue(for key: String) -> String?Parameters
keyproperty key.
-
setProperties(_:Extension methodoverwrite: ) Set the node’s properties values, optionally overwriting current values.
Declaration
Swift
public func setProperties(_ attrs: [String : String], overwrite: Bool = false)Parameters
attrsdictionary of properties.
overwriteoverwrite the current value, if one exists.
-
setValue(forKey:Extension method_: ) Sets a named SKTiled property. Returns the value, or nil if it does not exist.
Declaration
Swift
@available(*, deprecated, renamed: "setValue(for:﹚") public func setValue(forKey key: String, _ value: String)Parameters
keyproperty key.
valueproperty value.
-
removeProperty(forKey:Extension method) Remove a named
SKTiledproperty, returns the value as a string (if property exists).Declaration
Swift
@available(*, deprecated, renamed: "removeValue(for:﹚") public func removeProperty(forKey key: String) -> String?Parameters
keyproperty key.
-
getChild(uuid:Extension method) Returns a Tiled SpriteKit node with a matching unique ID.
Declaration
Swift
public func getChild(uuid: String) -> SKNode?Parameters
uuidunique Tiled node id to match.
Return Value
child
TiledObjectTypenode with the given unique id.
View on GitHub
Install in Dash
TiledObjectType Protocol Reference