Swiftpack.co - Package - backslash-f/cskscene

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.

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 MyClass: 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
    }
}

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: 1
Last commit: 1 week ago

Releases

v0.2.1 - 2021-02-20T14:40:16

Unlocks the version of the GCOverseer dependency, meaning it will always use its latest version by default.