Combine wrapper around Apple's Game Controller Framework.
- iOS 14
- macOS 11 (BigSur )
- Mac Catalyst 14
- tvOS 14
- Xcode 12
- Swift 5.3
import SpriteKit
import Combine
import GCOverseer
class GameScene: SKScene {
let gcOverseer = GCOverseer()
var cancellables = Set<AnyCancellable>()
override init(size: CGSize) {
super.init(size: size)
// ๐ฎ
gcOverseer.$isGameControllerConnected
.sink { isConnected in
// Do something
}
.store(in: &cancellables)
}
}
Property | Description |
---|---|
@Published var isGameControllerConnected: Bool |
Subscribe to this variable to keep track of connect / disconnect events of game controllers. |
API | Description |
---|---|
controllers() |
Returns all controllers that are connected to the device. E.g. Dualshock, Xbox, Siri Remote controllers, etc. |
extendedGamepadControllers() |
Returns all controllers supporting the extendedGamepad profile that are connected to the device. E.g. Dualshock, Xbox controllers, etc. |
dualshockControllers() |
Returns all DualShock controllers that are connected to the device. |
xboxControllers() |
Returns all Xbox controllers that are connected to the device. |
microGamepadControllers() |
Returns all controllers supporting the microGamepad profile that are connected to the device. E.g. Apple's Siri Remote. |
motionControllers() |
Returns all controllers supporting the motion profile that are connected to the device. |
controllerFor(playerIndex:) |
Returns the controller for the player 1, player 2, etc. |
enableLogging() / disableLogging() |
Enables / disables logging output. |
Use Xcode's built-in support for SPM.
or...
In your Package.swift
, add GCOverseer
as a dependency:
dependencies: [
.package(
url: "https://github.com/backslash-f/gcoverseer",
.upToNextMajor(from: "1.0.0")
)
]
Associate the dependency with your target:
targets: [
.target(
name: "YourTargetName",
dependencies: [
.product(
name: "GCOverseer",
package: "gcoverseer"
)
]
)
]
Run: swift build