Add catbox part 2

This commit is contained in:
Yash Karandikar 2022-04-05 12:21:08 -05:00
parent 05d6cf03e5
commit eaa68b12b2
Signed by: karx
GPG Key ID: A794DA2529474BA5
1 changed files with 14 additions and 0 deletions

14
content/blog/catbox2.md Normal file
View File

@ -0,0 +1,14 @@
+++
title = "Adventures in writing a game engine in Rust: Part 2"
date = "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"](https://wiki.libsdl.org/SDL_BlitSurface). 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](https://wiki.libsdl.org/SDL_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 `Sprite`s to the screen at an angle, without any ugly trails or flickering.
This marked the [first published version](https://crates.io/crates/cat-box/0.1.0) of cat-box on crates.io, and you can see how far it's come since then.
As always, the codeis on [my gitea](https://git.karx.xyz/karx/catbox) and published on [crates.io](https://crates.io/crates/cat-box). 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!