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).
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
- Synth (partial)
- Sprite
- System
For detailed instructions and documentation on how to get started creating a game using PlaydateKit, see here.
- Install a recent nightly Swift toolchain that supports the Embedded experimental feature.
- Install the Playdate SDK.
- Create a new repository using the PlaydateKitTemplate template.
- Build and run directly in the simulator using Xcode, or build using the command
swift package pdc
. When built usingswift package pdc
, the builtpdx
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
print(isChecked ? "checked!" : "not checked")
}
}
func update() -> Bool {
System.drawFPS()
return true
}
func gameWillPause() {
print("Paused!")
}
}
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.
If you create a game using PlaydateKit and would like it featured here, please open an issue or pull request! If you would like to demake a retro game or create a new one that demonstrates PlaydateKit's capabilities, feel free to add an example game in the Examples/
directory.
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.