SKTiledObject
@objc
public protocol SKTiledObject
Overview
The SKTiledObject
protocol defines a basic data structure for mapping custom Tiled
properties to SpriteKit objects. Objects conforming to this protocol will
automatically receive properties from the Tiled scene, unless supressed
by setting the object’s SKTiledObject.ignoreProperties
property.
Properties
Property | Description |
---|---|
uuid | Unique object id. |
type | Tiled object type. |
properties | Object of custom Tiled properties. |
ignoreProperties | Ignore Tiled properties. |
renderQuality | Resolution multiplier value. |
Instance Methods
Method | Description |
---|---|
parseProperties | Parse function (with optional completion block). |
Usage
// query a Tiled string property
if let name = tiledObject.stringForKey("name") {
tiledObject.name = name
}
// query a boolean property
let isDynamic = tiledObject.boolForKey("isDynamic") == true
-
▶︎uuid
Unique object id (layer & object names may not be unique).
Declaration
Swift
var uuid: String { get set }
-
▶︎type
Object type.
Declaration
Swift
var type: String! { get set }
-
Storage for custom Tiled properties.
Declaration
Swift
var properties: [String : String] { get set }
-
Ignore custom properties.
Declaration
Swift
var ignoreProperties: Bool { get set }
-
Parse function (with optional completion block).
Declaration
Swift
func parseProperties(completion: (() -> Void)?)
-
Render scaling property.
Declaration
Swift
var renderQuality: CGFloat { get }
-
▶︎hash(into:
Extension method) Hash id.
Declaration
Swift
public func hash(into hasher: inout Hasher)
-
▶︎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 }
Parameters
key
String
key to query.Return Value
String?
value for the given key. -
▶︎hasProperties
Extension methodReturns true if the node has stored properties.
Declaration
Swift
public var hasProperties: Bool { get }
Return Value
Bool
properties are not empty. -
▶︎hasKey(_:
Extension method) Returns true if the node has the given SKTiled property (case insensitive).
Declaration
Swift
public func hasKey(_ key: String) -> Bool
Parameters
key
String
key to query.Return Value
Bool
properties has a value for the key. -
▶︎boolForKey(_:
Extension method) Returns a boolean value for the given key.
Declaration
Swift
public func boolForKey(_ key: String) -> Bool
Parameters
key
String
properties key.Return Value
Bool
value for properties key. -
▶︎stringForKey(_:
Extension method) Returns a string for the given SKTiled key.
Declaration
Swift
public func stringForKey(_ key: String) -> String?
Parameters
key
String
properties key.Return Value
String
value for properties key. -
▶︎intForKey(_:
Extension method) Returns a integer value for the given key.
Declaration
Swift
public func intForKey(_ key: String) -> Int?
Parameters
key
String
properties key.Return Value
Int?
value for properties key. -
▶︎doubleForKey(_:
Extension method) Returns a float value for the given key.
Declaration
Swift
public func doubleForKey(_ key: String) -> Double?
Parameters
key
String
properties key.Return Value
Double?
value for properties key. -
▶︎setValue(forKey:
Extension method_: ) Sets a named SKTiled property. Returns the value, or nil if it does not exist.
Declaration
Swift
public func setValue(forKey key: String, _ value: String)
Parameters
key
String
property key.value
String
property value. -
▶︎removeProperty(forKey:
Extension method) Remove a named SKTiled property, returns the value as a string (if property exists).
Declaration
Swift
public func removeProperty(forKey key: String) -> String?
Parameters
key
String
property key.Return Value
String?
property value (if it exists). -
▶︎propertiesString
Extension methodReturns a string representation of the node’s properties.
Declaration
Swift
public var propertiesString: String { get }