GCOverseer

0.2.2

Observe and manage game controllers using Combine 🎮
backslash-f/gcoverseer

What's New

v0.2.2

2021-02-20T14:28:08Z

Fixes an issue where the initial isConnected value would be false even when controllers were connected.

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

GCOverseer

Combine wrapper around Apple's Game Controller Framework.

Tested Platforms

  • iOS 14+
  • macOS 11+ (BigSur+)
  • Mac Catalyst 14+
  • tvOS 14+
  • Xcode 12+
  • Swift 5.3+

Usage Examples

Handle Connected / Disconnected Events

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)
    }
}

Available Properties

Property Description
@Published var isGameControllerConnected: Bool Subscribe to this variable to keep track of connect / disconnect events of game controllers.

Available APIs

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.

Integration

Xcode

Use Xcode's built-in support for SPM.

or...

Package.swift

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

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

Associate the dependency with your target:

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

Run: swift build

Description

  • Swift Tools 5.3.0
View More Packages from this Author

Dependencies

Last updated: Sun Apr 21 2024 19:13:27 GMT-0900 (Hawaii-Aleutian Daylight Time)