Let’s get started with a new application where we will implement out Text Gem game framework. You should be somewhat familiar with developing Rust if you want to follow along. If you don’t know Rust well, this could be a good way to start learning!
Prerequisites
You need to install Rust using rustup. Once you have Rust installed, we’ll create a new project to start coding.
Terminal
1
2
3
4
5
6
7
8
# Create a new Rust projectcargo new textgem
# Go into the newly-created project foldercd textgem
# Run the Hello, World! default applicationcargo run # You should see "Hello, world!" appear in your terminal
Create Application Window
Next up we will want to create a window that we can draw to. In order to do this, we’ll need to add Bevy as a dependency to our project and modify the main.rs file.
cargo.toml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[package]name="textgem"version="0.1.0"edition="2021"[dependencies]bevy="0.12"# Enable a small amount of optimization in debug mode[profile.dev]opt-level=1# Enable high optimizations for dependencies (incl. Bevy), but not for our code:[profile.dev.package."*"]opt-level=3
Once you have modified these two files, run the application again using cargo run. You should now see a blank window appear on your screen.
Add TextGem Plugin
Bevy uses a plugin system to add logic to an application. Everything in Bevy is initialized using a plugin by default, including the windowing framework and core rendering framework. It is convenient to structure our TextGem application code as a plugin. To do this, we need to create an implementation of the Plugin trait and add it to the Bevy application. Update main.rs with out TextGem plugin code.
Now if you run your application with cargo run you should see a blue cube in the middle of the window.
Next Up…
That does it for this post. You have successfully built your first Bevy application, congratulations! In the next post, we will start to render graph paper!
Full code for this post can be found here: TextGem Post 1.