Other Functions

The following functions are available globally.

  • Send an alert. This a convenience utility to create an NSAlert with some properties.

    Declaration

    Swift

    func sendAlert(_ message: String,
                   withTitle: String?,
                   level: NSAlert.Style,
                   handler: @escaping ((NSApplication.ModalResponse) -> Void))

    Parameters

    message

    The message of the alert.

    withTitle

    The title of the alert.

    level

    The level of importance for the alert.

    handler

    An escaping closure that handles the alert’s response when given.

  • Send an alert. This a convenience utility to create an NSAlert with some properties.

    Declaration

    Swift

    func sendAlert(_ message: String,
                   withTitle: String?,
                   level: NSAlert.Style,
                   attachToMainWindow: Bool,
                   handler: @escaping ((NSApplication.ModalResponse) -> Void))

    Parameters

    message

    The message of the alert.

    withTitle

    The title of the alert.

    level

    The level of importance for the alert.

    attachToMainWindow

    Whether to attach the alert to the main window.

    handler

    An escaping closure that handles the alert’s response when given.

  • Send a confirmation alert. This a convenience utility to create an NSAlert with some properties.

    Declaration

    Swift

    func confirm(_ message: String,
                 withTitle: String?,
                 level: NSAlert.Style,
                 handler: @escaping ((NSApplication.ModalResponse) -> Void))

    Parameters

    message

    The message of the alert.

    withTitle

    The title of the alert.

    level

    The level of importance for the alert.

    handler

    An escaping closure that handles the alert’s response when given.

  • Get a list of frames from an atlas.

    Declaration

    Swift

    public func animated(fromAtlas atlas: SKTextureAtlas, reversable: Bool = false) -> [SKTexture]

    Parameters

    atlas

    The atlas to read animation frames from.

    reversable

    Whether the animation should play in reverse afterwards. Defaults to false.

    Return Value

    A list of textures that make up the animation.

  • Get the type of tile from a given definition.

    Declaration

    Swift

    public func getTileType(fromDefinition tile: SKTileDefinition) -> GameTileType

    Parameters

    tile

    The tile definition to look up the type for.

    Return Value

    The respective tile type as GameTileType.

  • Create a physics body for a wall with a given texture.

    Declaration

    Swift

    public func getWallPhysicsBody(with texture: SKTexture) -> SKPhysicsBody

    Parameters

    texture

    The texture to assign the wall’s physics body to.

    Return Value

    A physics body that matches the texture.

  • Create a physics body for a wall with a given texture.

    Declaration

    Swift

    public func getWallPhysicsBody(with textureName: String) -> SKPhysicsBody

    Parameters

    texture

    The texture to assign the wall’s physics body to.

    Return Value

    A physics body that matches the texture.

  • Create a physics body for a heavy object with a given texture.

    Declaration

    Swift

    public func getHeavyObjectPhysicsBody(with texture: SKTexture) -> SKPhysicsBody

    Parameters

    texture

    The texture to assign the object’s physics body to.

    Return Value

    A physics body that matches the texture.

  • Create a physics body for a heavy object with a given texture.

    Declaration

    Swift

    public func getHeavyObjectPhysicsBody(with textureName: String) -> SKPhysicsBody

    Parameters

    texture

    The name of the texture to assign the object’s physics body to.

    Return Value

    A physics body that matches the texture.

  • Read a property list file and get the contents as a dictionary.

    Declaration

    Swift

    func plist(from plistName: String) -> NSDictionary?

    Parameters

    plistName

    The name of the property lsit file to get the data of.

    Return Value

    A dictionary representation of the file, or a null value if none is found.