Playbit - a framework for creating cross-platform Playdate games

I've been working on a framework alongside my Playdate projects to make cross-platform development easier. While none of my prototypes have turned into full games yet, I feel like my framework as reached a stage where its worth sharing :tada:

playbit-example

Playbit is a framework for creating cross-platform Playdate games from a single Lua codebase. To accomplish this, it has two key components:

  • A reimplemention the Playdate API in Love2D.
  • A build system that utilizes LuaPreprocess to strip/inject platform dependent code.

This project is in active development and has not reached a stable 1.0 release yet. There will be bugs and missing features - use in a production environment at your own risk.

For more information, please see the docs.

I'll be monitoring this thread, but prefer that feature requests and bug reports be added to the Github issue tracker.

Also community involvement is welcome - please feel free to open a pull request :heart:

20 Likes

How exciting! I'll be trying this.

Very useful! I like the Luapreprocess idea.

2 Likes

Awesome! Please let me know if you have any trouble getting it working. I feel pretty good about the docs, but I'm sure there's a few holes here and there :sweat_smile:

This is incredibly fascinating, and it is huge step down the road to getting a functioning web-player for playdate projects.

Are there any plans for the C side of things?

1 Like

I havent explored web, but there are some tools for building love2d games for web, like this one GitHub - Davidobot/love.js: LÖVE ported to the web using Emscripten, updated to the latest Emscripten and LÖVE (v11.4)

I dont have any plans for C. I really enjoy Lua and wanted to create something that didnt require mucking around in C. However...it probably would have been more sane to approach this from the C side :sweat_smile:

1 Like

I know @donald.hays came up with his own approach to this love2d problem.

I'm trying to find it, but no joy so far.

Small change, but big impact: Playbit's build script now supports Mac! Special thanks to @notpeter :tada:

3 Likes

This is an awesome tool, thank you for making this! I'm struggling a bit to get my game running, as I'm new to Lua and I don't fully understand how the whole require module pipeline works. When I get my game launched in Love, I get the following error as it attempts to load one of the scripts:

Error: main.lua:112: module 'scripts.AnimatedSprite' not found:
        no field package.preload['scripts.AnimatedSprite']
        no 'scripts/AnimatedSprite' in LOVE game directories.
        no file 'scripts/AnimatedSprite' in LOVE paths.
        no file './scripts/AnimatedSprite.lua'
        no file '/usr/local/share/luajit-2.1.0-beta3/scripts/AnimatedSprite.lua'
        no file '/usr/local/share/lua/5.1/scripts/AnimatedSprite.lua'
        no file '/usr/local/share/lua/5.1/scripts/AnimatedSprite/init.lua'
        no file './scripts/AnimatedSprite.so'
        no file '/usr/local/lib/lua/5.1/scripts/AnimatedSprite.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
        no file './scripts.so'
        no file '/usr/local/lib/lua/5.1/scripts.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
        [love "boot.lua"]:345: in function <[love "boot.lua"]:341>
        [C]: in function 'require'
        main.lua:112: in main chunk
        [C]: in function 'require'
        [love "boot.lua"]:316: in function <[love "boot.lua"]:126>
        [C]: in function 'xpcall'
        [love "boot.lua"]:355: in function <[love "boot.lua"]:348>
        [C]: in function 'xpcall'

The script in question here is from GitHub - Whitebrim/AnimatedSprite: Sprite class extension with imagetable animation and finite state machine support for @Playdate. I originally added it to my project with toybox but that seemed to give me problems so in this case I just copied the file directly into my source folder. I'm using the import macros to import everything like so:

@@IMPORT('scripts/AnimatedSprite')

In my case most of my scripts are classes, but I note a different approach is used in your playbit template:

module = {}
playbitIntro = module

with module prepended to all your functions. Is this required for the imports to work?

Awesome stuff! I planned to port some of my PlayDate games to Love someday and it could greatly help me. I’m looking forward to see how your project will grow :blush:

1 Like

I don't fully understand how the whole require module pipeline works

This tripped me up too when I first started Playdate dev, and Playbit probably muddies the waters more :sweat_smile: Simple explanation:

When I get my game launched in Love, I get the following error as it attempts to load one of the scripts:

Hmm I'm not positive what the exact issue is here but I'm very certain Whitebrim's AnimatedSprite script won't work with Playbit, at least not without some modifications. Partly because AnimatedSprite uses Playdate's import() function, but also because it uses CoreLibs/object and
CoreLibs/sprites from the Playdate SDK which I have yet to implement into Playbit :sweat_smile:

I know the community uses this script a lot, so I'll move the object and sprite implementation up my task list!

In my case most of my scripts are classes, but I note a different approach is used in your playbit template:

module = {}
playbitIntro = module

with module prepended to all your functions. Is this required for the imports to work?

This pattern is not required for imports to works. This was something I picked up early on, which mainly just makes it easier to rename things.

However, if by "classes" you mean the ones provided by CoreLibs/object then, as noted above, this won't work at the moment since I haven't implemented that into Playbit yet :disappointed:

In my projects, I've been rolling with a lot of my own code, so I've been mostly focused on the core parts of the Playdate SDK (rendering, input, audio, etc) and not the utility ones, but they'll get in there eventually!

Got it, this makes a lot more sense. Since I'm structuring all my code with the CoreLibs/object "class" pattern (having no idea that was not a core part of Lua :stuck_out_tongue: ), and many sprites, I'll definitely need to hold off a bit before implementing Playbit. Appreciate the thorough response!

1 Like

What is the best way to get started developing games with Playbit? Do I start a regular play-date project and then port parts of the code over or is there some better way?

That's the way to do it.

Depends on your project!

If you have an existing project you want to add Playbit to, see this documentation.

If you're starting a new project, I highly recommend started from the Playbit template.

If you get stuck feel free to report back here. I'm always looking for ways to make the documentation clearer :slightly_smiling_face:

This is awesome. I intend to use Love2D once I finish my game, to port it to steam.

But I was thinking more of making sure it works 100% first in playdate, and then making a port. Is it possible using this tool? Or would I need to program the entire thing from scratch using it?

From the looks of it, seems I can add it at the end and it will work well!

ALthought I will probably be wanting to add color, which will probably be another issue

Disclaimer: the project is still in active development, and has not yet reach an active 1.0 release. What is there is very functional tho - it just depends on what parts of the PD SDK you're using as it might not have been implemented in Playbit yet.

With that all said, my recommendation would be to wait until after your Playdate release. While its possible to add mid development, in its current state it may be more disruptive than what its worth.

However if you'd just like to utilize the build scripts and preprocessor features, then you could add Playbit now. Those features are very stable and you dont need to incorporate the rest of Playbit. I probably should add some steps to the docs for people who just want to use it for this :sweat_smile:

I've written a Love2d shader explicitly for emulating Playdate graphics, but it could be easily disabled to allow color in textures to draw normally.

2 Likes

perfect! thank you!

this will help a lot for sure