Adventures in writing a game engine in Rust: Part 2

2022-04-05

The next thing I had to do was to add support for rendering images. The first thing I did was to just create a Sprite struct, which stored the image and the destination rectangle. This rectangle was used to set the properties of the drawn image on the screen.

Initially, I used an SDL technique called "surface blitting". It worked well at first, however, when moving the destination rectangle around, old copies of the sprite were not being cleared off the screen, even when using the SDL canvas's clear method. The sprite would also flicker with each frame, because it was being redrawn twice on each frame.

Then, I discovered a method in SDL called RenderCopyEx. Aside from fixing all the issues mentioned above, it also included options to angle and flip the texture before drawing it to the screen. Now, users could draw Sprites to the screen at an angle, without any ugly trails or flickering.

This marked the first published version of cat-box on crates.io, and you can see how far it's come since then.

As always, the codeis on my gitea and published on crates.io. If you spot an issue, feel free to shoot me an email with a description of the issue or even a patch which fixes it!


home - projects - blog - built with zola