PD QR Code Gen - a simple tool for generating pre-rendered QR codes for your games

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:

pdqrcodegen-demo

And here's the generated QR code:

qrcode

You can download a compiled version here for your Simulator:

pdqrcodegen.pdx.zip (29.3 KB)

Or get the source at:

How to Use

  1. Launch the Playdate Simulator
  2. Open pdqrcodegen.pdx in the Simulator
  3. Open the Lua console in the Simulator
  4. 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. :sparkles:

Hope this helps someone. :playdate_heart: I know I'll be using it for my projects where I don't need on-demand QR codes.

5 Likes

I don't mean to rude, but why run an app in the simulator instead of just using an online qrcode generator

Not rude, it's a good question! There are few reasons:

  • It's helpful to do it through the Playdate Simulator to get the sizing correct
  • I'm not entirely sure how well downsizing a web-generated QR code will translate to Playdate and if it could cause it to not be readable
  • It was helpful for learning how to generate QR codes and figured I'd share :smile:

Now that I think about it, being able to see the sizing is pretty nice and I always enjoy learning new things