Playdate_Api_SDL2

An attempt to reimplement the Playdate Handheld C Api in SDL2


Project maintained by joyrider3774 Hosted on GitHub Pages — Theme by mattgraham

Playdate Api SDL2

An attempt to reimplement the Playdate Handheld C Api in SDL2

I attempted to reimplement the Playdate API headers in SDL2, I’ve used this to create windows (and linux) binaries to for my playdate game’s from unaltered source code for the playdate. It’s probably done in a very bad way but it does seem to work for my games and other games on github.

Implemented

Graphics:

System:

Sound:

Sprites:

File:

JSON:

Not Implemented

Graphics:

System:

Sound:

Other:

how to

  1. place your playdate game’s unaltered source code files inside src/srcgame (so the contents of your “src” folder)
  2. place your playdate game’s Source directory (containing assets) inside Source (so the contents of your “Source” folder) + make sure it contains a pdxinfo file with a bundleID set (it’s used to determine unique save folder)
  3. OPTIONALLY (fnt loading is now supported, ttf no longer required): Convert fonts (fnt+png) files to TTF files: by using bitsnpicas to export to BDF file, then open BDF file in fontforge studio and export to ttf. So that the ttf font files match exactly as on the playdate, the export from bitsnpicas to ttf does not help here as it does not export in same size fonts as used on playdate.

    Another more easier way to convert the playdate fnt files to loadable ttf files with same size is to open the playdate font in bitsnpicas and then inside bitsnpicase export the font as a windows 3.1 fnt file. Then rename the fnt files to .ttf. (recent) SDL2_ttf (versions) seems to be able to load these fonts as well.

  4. Compile using the provided makefile.
  5. If all goes well compiled binary should be named game(.exe) in Source directory

colorize your games

if you place a “Source1” or “Source2”, … folder inside the “Source” folder you can swap source folders by press F3 when the game is running. inside these additional source folders, you replicate the same folder structure as in the original Source folder but you can use different files for example colorized graphics. in order for this to work correctly you need to make sure that you implemented the kEventTerminate event and free your game’s assets / alloced memory when it’s called, otherwise you’ll have memory leaks. It works by first calling kEventTerminate and then kEventInit again so you need to make sure that you also reset global variables inside kEventInit. you can also provide a colors.ini file to determine the colors used for black and white. You need to make sure that the clear color lies between black and white. For an example on this i suggest to check some of my playdate game repo’s.

Simple palette swaps using only colors.ini

Besides creating new assets folders you can also just created “SourceX” folders with a colors.ini for simple palette swaps. Here is an example palette swap for gameboy color graphics. The rules are that Black < BlachThreshold < Clear < Whitethreshold < White and the thresholds should be near the clear color. pd_api_gfx_color_force_black_white=1 is what makes graphics be converted to 1 bit graphics setting it 0 will retain original assets like if you want to replace assets with colored assets but still use different colors for main api drawing functions

pd_api_gfx_color_clear_r=100
pd_api_gfx_color_clear_g=110
pd_api_gfx_color_clear_b=68
pd_api_gfx_color_white_r=168
pd_api_gfx_color_white_g=182
pd_api_gfx_color_white_b=104
pd_api_gfx_color_black_r=15
pd_api_gfx_color_black_g=56
pd_api_gfx_color_black_b=15
pd_api_gfx_color_whitetreshold_r=102
pd_api_gfx_color_whitetreshold_g=112
pd_api_gfx_color_whitetreshold_b=70
pd_api_gfx_color_blacktreshold_r=98
pd_api_gfx_color_blacktreshold_g=108
pd_api_gfx_color_blacktreshold_b=66
pd_api_gfx_color_force_black_white=1

credits

Showcase video

Playdate SDL2 Api Showcase Video

example games