PyObjC GameplayKit

12.1 · active · verified Tue Apr 14

PyObjC-framework-gameplaykit provides Python bindings for Apple's GameplayKit framework on macOS. It enables Python applications to leverage game development utilities, including random number generation, pathfinding, AI behaviors, and more, directly from Python. The current version is 12.1, with releases generally aligning with macOS SDK updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import and use a basic GameplayKit feature, `GKARC4RandomSource`, to generate random numbers and shuffle arrays. It highlights the `alloc().init()` pattern for Objective-C object instantiation via PyObjC.

import GameplayKit
import objc # For general PyObjC operations, though not explicitly used here beyond object instantiation

# Initialize a basic random number generator from GameplayKit
# The alloc().init() pattern is common for Objective-C object creation
random_source = GameplayKit.GKARC4RandomSource.alloc().init()

# Generate a random integer within a bound (0 to 99)
random_int = random_source.nextIntWithUpperBound_(100)
print(f"Generated random number (0-99): {random_int}")

# Example using a different random distribution
shuffled_array = random_source.arrayByShufflingObjectsInArray_(["apple", "banana", "cherry", "date"])
print(f"Shuffled array: {shuffled_array}")

view raw JSON →