OUR EXPERT
QUICK TIP
QUICK TIP
GETTING STARTED!
QUICK TIP
QUICK TIP
OPTIMISING CODE
David Bolton has been programming games on Raspberry Pis for several years and has nearly finished writing an ebook about learning to program games in C.
Note that the responsiveness of a Raspberry Pi is affected by the quality of SD card. This can be quite confusing but the A-rated SD cards, such as A2, are among the fastest. You don’t need the likes of V90, which are better suited for video cameras. A faster SD card means compiles are faster and programs load more.
Try to limit using printf/sprintf as it can be slow. Sometimes it’s inevitable, as in SetWindow Caption(). Try printing into a texture before the game starts and use SDL_ RenderCopy to display it.
To install Visual Studio Code, browse to https://code.visualstudio.com/ Download and grab the ARM32 or ARM64 DEB build. Install the DEB and once in VS Code, install the C/C++ extension; the fifth one down is usually the Microsoft C/C++ extension. Click the Install button. Now install Clang with:
SD cards can fail. Buy a cheap USB memory stick (or ideally two) and save your source code on to it. That way, if the worst happens, you’ve only lost the changes since the last backup. Set up a cron job to back up your files.
In the game loop, separate the functionality, such as moving missiles or growing explosions, from the code that does the drawing. This keeps the design clean and makes it easier to time your code.
With games, it’s vital that you figure out which parts of your code are slow, and make them faster if you can, so you need to time your code. Linux provides a high-speed timer; a Pi 4B CPU runs at 1.5GHz, so the timer counts from 0 to 1,500,000,000 every second.
OUR EXPERT
David Bolton has been programming games on Raspberry Pis for several years and has nearly finished writing an ebook about learning to program games in C.
$ sudo apt install clang