SKObjectGroup
public class SKObjectGroup : SKTiledLayerObject
Overview
The SKObjectGroup
class is a container for vector object types. Most object properties can be set on the parent SKObjectGroup
which is then applied to all child objects.
Properties
Property | Description |
---|---|
count | Returns the number of objects in the layer. |
showObjects | Toggle visibility for all of the objects in the layer. |
lineWidth | Governs object line width for each object. |
debugDrawOptions | Debugging display flags. |
Methods
Method | Description |
---|---|
addObject | Returns the number of objects in the layer. |
removeObject | Toggle visibility for all of the objects in the layer. |
getObject(withID:) | Returns an object with the given id, if it exists. |
Usage
Adding a child object with optional color override:
objectGroup.addObject(myObject, withColor: SKColor.red)
Querying an object with a specific name:
let doorObject = objectGroup.getObject(named: "Door")
Returning objects of a certain type:
let rockObjects = objectGroup.getObjects(ofType: "Rock")
-
Toggle visibility for all of the objects in the layer.
Declaration
Swift
public var showObjects: Bool { get set }
-
▶︎count
Returns the number of objects in this layer.
Declaration
Swift
public var count: Int { get }
-
Controls antialiasing for each object
Declaration
Swift
override public var antialiased: Bool { get set }
-
Governs object line width for each object.
Declaration
Swift
public var lineWidth: CGFloat { get set }
-
Render scaling property.
Declaration
Swift
override public var renderQuality: CGFloat { get set }
-
Debug visualization options.
Declaration
Swift
override public var debugDrawOptions: DebugDrawOptions { get set }
-
Add an
SKTileObject
object to the objects set.Declaration
Swift
public func addObject(_ object: SKTileObject, withColor: SKColor? = nil) -> SKTileObject?
Parameters
object
SKTileObject
object.withColor
SKColor?
optional override color (otherwise defaults to parent layer color).Return Value
SKTileObject?
added object. -
Remove an
SKTileObject
object from the object set.Declaration
Swift
public func removeObject(_ object: SKTileObject) -> SKTileObject?
Parameters
object
SKTileObject
object.Return Value
SKTileObject?
removed object. -
▶︎draw()
Render all of the objects in the group.
Declaration
Swift
public func draw()
-
Set the color for all objects.
Declaration
Swift
override public func setColor(color: SKColor)
Parameters
color
SKColor
object color.force
Bool
force color on objects that have an override. -
Set the color for all objects.
Declaration
Swift
override public func setColor(hexString: String)
Parameters
color
SKColor
object color.force
Bool
force color on objects that have an override. -
Returns an array of object names.
Declaration
Swift
public func objectNames() -> [String]
Return Value
[String]
object names in the layer. -
Returns an object with the given id.
Declaration
Swift
public func getObject(withID id: Int) -> SKTileObject?
Parameters
id
Int
Object id.Return Value
SKTileObject?
-
Return text objects with matching text.
Declaration
Swift
public func getObjects(withText text: String) -> [SKTileObject]
Parameters
withText
String
text string to match.Return Value
[SKTileObject]
array of matching objects. -
Return objects with the given name.
Declaration
Swift
public func getObjects(named: String) -> [SKTileObject]
Parameters
named
String
Object name.Return Value
[SKTileObject]
array of matching objects. -
Return all child objects.
Declaration
Swift
public func getObjects() -> [SKTileObject]
Return Value
[SKTileObject]
array of matching objects. -
Return objects of a given type.
Declaration
Swift
public func getObjects(ofType: String) -> [SKTileObject]
Parameters
type
String
object type.Return Value
[SKTileObject]
array of matching objects.
-
Return tile objects.
Declaration
Swift
public func tileObjects() -> [SKTileObject]
Return Value
[SKTileObject]
objects with a tile gid. -
Return tile object(s) matching the given global id.
Declaration
Swift
public func tileObjects(globalID: Int) -> [SKTileObject]
Parameters
globalID
Int
global id to query.Return Value
SKTileObject?
removed object. -
Create and add a tile object with the given tile data.
Declaration
Swift
public func newTileObject(data: SKTilesetData) -> SKTileObject
Parameters
data
SKTilesetData` tile data.
Return Value
SKTileObject
created tile object.
-
Return text objects.
Declaration
Swift
public func textObjects() -> [SKTileObject]
Return Value
[SKTileObject]
text objects.
-
Called when the layer is finished rendering.
Declaration
Swift
override public func didFinishRendering(duration: TimeInterval = 0)
Parameters
duration
TimeInterval
fade-in duration.
-
Run animation actions on all tile objects.
Declaration
Swift
override public func runAnimationAsActions()
-
Remove tile object animation.
Declaration
Swift
override public func removeAnimationActions(restore: Bool = false)
Parameters
restore
Bool
restore tile/obejct texture.
-
Update the object group before each frame is rendered.
Declaration
Swift
override public func update(_ currentTime: TimeInterval)
Parameters
currentTime
TimeInterval
update interval.
-
Returns an object with the given name.
Declaration
Swift
@available(*, deprecated, message: "use `getObjects(named:,recursive:﹚` instead") public func getObject(named: String) -> SKTileObject?
Parameters
named
String
Object name.Return Value
SKTileObject?
-
Render all of the objects in the group.
Declaration
Swift
@available(*, deprecated, renamed: "SKObjectGroup.draw(﹚") public func drawObjects()
-
Parse the object group’s properties.
Declaration
Swift
override public func parseProperties(completion: (() -> Void)?)