A custom SKScene subclass with debug options enabled by default and the ability to observe game controllers via GCOverseer.
Subclass CSKScene to have access to its properties:
class MyScene: CSKScene { ... }All debug settings are enable by default (in DEBUG mode):
showsFPSshowsFieldsshowsPhysicsshowsDrawCountshowsNodeCountshowsQuadCount
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 disabledsink 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`
}
}| 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". |
- |
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
}
}A custom SKNode subclass that provides observable properties based on KVO + Combine.
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`
}
}Use Xcode's built-in support for SPM.
or...
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