PlaydateKit

main

Create games for Playdate using Swift.
finnvoor/PlaydateKit

PlaydateKit Logo

PlaydateKit

PlaydateKit provides easy to use Swift bindings for the Playdate C API. PlaydateKit aims to be as Swift-y as possible, replacing error pointers with throwable functions, avoiding the use of pointers and memory management as much as possible, and adding documentation comments to all functions (copied from the Playdate SDK docs).

Status

PlaydateKit provides (almost) full coverage of the Playdate C API. PlaydateKit adds wrapper types for some values (Sprite, Bitmap, FileHandle, etc) that automatically manage the allocation/deallocation of resources. While I have attempted to closely follow the C API specifications, much of it is untested, so if you run into an unexpected issue or can't do something with the Swift API, please open an issue!

Currently, the following sections of the API are implemented:

  • Display
  • File
  • Graphics
  • JSON
  • Lua
  • Scoreboards
  • Sound
    • FilePlayer
    • SamplePlayer
  • Sprite
  • System

Usage

For detailed instructions and documentation on how to get started creating a game using PlaydateKit, see here.

Summary

  1. Install a recent nightly Swift toolchain that supports the Embedded experimental feature.
  2. Install the Playdate SDK.
  3. Create a new repository using the PlaydateKitTemplate template.
  4. Build and run directly in the simulator using Xcode, or build using the command swift package pdc. When built using swift package pdc, the built pdx game file will be located at .build/plugins/PDCPlugin/outputs/PlaydateKitTemplate.pdx and can be opened in the Playdate simulator.

Your PlaydateGame object manages the game lifecycle, receiving events such as gameWillPause and deviceWillSleep.

import PlaydateKit

final class Game: PlaydateGame {
    init() {
        System.addCheckmarkMenuItem(title: "check me") { isChecked in
            System.log(isChecked ? "checked!" : "not checked")
        }
    }

    func update() -> Bool {
        System.drawFPS()
        return true
    }

    func gameWillPause() {
        System.log("Paused!")
    }
}

Contributing

I'm happy to accept contributions on this project, whether it's bug fixes, implementing missing features, or opening an issue. Please try to follow the existing conventions/style in the project. Code should be formatted before merge using swiftformat ., but I can run this before merging if you don't want to install swiftformat.

If you create a game using PlaydateKit and would like it listed here, please open an issue or pull request! I am also hoping to add some simple games to an Examples/ directory in this repo if anyone wants to demake a retro game or create a new one that demos PlaydateKit.

Acknowledgements

PlaydateKit was inspired by and would not be possible without the excellent work done by @rauhul on swift-playdate-examples. Specifically, PlaydateKit was created due to the note in the swift-playdate-examples repo:

It is not intended to be a full-featured Playdate SDK so please do not raise PRs to extend the Playdate Swift overlay to new areas.

Description

  • Swift Tools 5.10.0
View More Packages from this Author

Dependencies

  • None
Last updated: Fri Dec 20 2024 23:36:48 GMT-1000 (Hawaii-Aleutian Standard Time)