Swiftpack.co -  backslash-f/cskscene as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
backslash-f/cskscene
A custom SKScene subclass with debug options enabled by default and the ability to observe game controllers.
.package(url: "https://github.com/backslash-f/cskscene.git", from: "v0.2.4")

swift-version swift-package-manager platforms ci-status license

CSKScene

A custom SKScene subclass with debug options enabled by default and the ability to observe game controllers via GCOverseer.

Usage Examples

Subclass CSKScene to have access to its properties:

class MyScene: CSKScene { ... }

Debug Settings

All debug settings are enable by default (in DEBUG mode):

  • showsFPS
  • showsFields
  • showsPhysics
  • showsDrawCount
  • showsNodeCount
  • showsQuadCount

To disable all options at once:

let debugSettings = DebugSettings(disableAll: true)
let myScene = CSKScene(size: someSize, debugSettings: debugSettings)

To disable some options:

let debugSettings = DebugSettings(showsFPS: false, showsPhysics: false, showsNodeCount: false)
let myScene = CSKScene(size: someSize, debugSettings: debugSettings)

It's also possible to change debug settings after initialization:

let myScene = CSKScene(size: someSize) // All debug settings are enabled by default...
myScene.debugSettings = DebugSettings(showsFields: false, showsQuadCount: false) // ... but these will be disabled

Observe Game Controllers

sink into the gcOverseer to keep track of connect / disconnect events of game controllers. E.g.:

class MyScene: CSKScene {
    func observeGameControllers() {
        gcOverseer.$isGameControllerConnected // `gcOverseer` from parent `CSKScene`
            .sink { isConnected in
                // Do something
            }
            .store(in: &cancellables) // `cancellables` from parent `CSKScene`
    }
}

Available Properties

Property Description Notes
var viewTop: CGFloat The "highest SKScene point" converted from the "highest SKView point". -
var viewBottom: CGFloat The "lowest SKScene point" converted from the "lowestSKView point". -
var viewLeft: CGFloat The "leftmost SKScene point" converted from the "leftmostSKView point". -
var viewRight: CGFloat The "rightmost SKScene point" converted from the "rightmostSKView point". -
var insets: UIEdgeInsets The insets used to determine the safe area of the window. iOS, tvOS and Mac Catalyst only, as it relies on UIEdgeInsets.

Default Values

These properties have the following default values:

Property name Default value Notes
ignoresSiblingOrder true Prevents arbitrary z positions that may change every time a new frame is rendered.
isMultipleTouchEnabled true Surprinsingly this had to be set to true to support multiple touches when working with SceneView / SwiftUI.

To set then to false, override CSKScene.didMove(to:) in your subclass. For example:

class MyScene: CSKScene {
    override func didMove(to view: SKView) {
        super.didMove(to: view)
        view.ignoresSiblingOrder = false
        view.isMultipleTouchEnabled = false
    }
}

CSKNode

A custom SKNode subclass that provides observable properties based on KVO + Combine.

Usage Examples

Subscribe to didAttachToParent to get informed whenever the node is attached to or detached from a parent node.

class MyNode: CSKNode {

    override init() {
        super.init()
        sinkOnParentChanges()
    }

    func sinkOnParentChanges() {
    $didAttachToParent // `didAttachToParent` from parent `CSKNode`
        .sink { [weak self] isAttachedToParent in
            if isAttachedToParent {
                // Setup your node 👈🏻
            }
        }
        .store(in: &cancellables) // `cancellables` from parent `CSKNode`
    }
}

Integration

Xcode

Use Xcode's built-in support for SPM.

or...

Package.swift

In your Package.swift, add CSKScene as a dependency:

dependencies: [
  .package(url: "https://github.com/backslash-f/cskscene", from: "0.1.0")
],

Associate the dependency with your target:

targets: [
  .target(name: "App", dependencies: ["CSKScene"])
]

Run: swift build

GitHub

link
Stars: 2
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

v0.2.4
2 weeks ago

Adds the new CSKnode class.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API