I was working on adding a QR code to my game that links to my other games. When reading through Inside Playdate, it says:
If you know ahead of time what data you plan to encode, it is much faster to pre-generate the QR code, store it as a .png file in your game, and draw the .png at runtime. You can use
playdate.simulator.writeToFile()
to create this .png file.
So I made a little tool that does just that! It's called PD QR Code Gen. You launch it in the Simulator, send a message via the Lua console with !msg https://example.com
, and your QR code is generated and saved to your computer.
Here's a demo of it in action:
And here's the generated QR code:
You can download a compiled version here for your Simulator:
pdqrcodegen.pdx.zip (29.3 KB)
Or get the source at:
How to Use
- Launch the Playdate Simulator
- Open pdqrcodegen.pdx in the Simulator
- Open the Lua console in the Simulator
- Type in
!msg HTTPS://EXAMPLE.COM
(all caps makes lighter QR codes)
The QR code will be generated. When it's done, it gets saved on your computer
at ~/qrcode.png
and displayed in the Simulator for testing.
Show the QR code in your game
Put qrcode.png
somewhere in your source
directory. Create a new image and draw it:
local qrCode = playdate.graphics.image.new("qrcode.png")
assert(qrCode, "Failed to load QR code image")
qrCode:draw(20, 60)
Hooray
This little tool is also a decent and simple example of how to use the asynchronous QR code API.
Hope this helps someone. I know I'll be using it for my projects where I don't need on-demand QR codes.