Hello, World!
Overview
Walkthrough
Initialize the Project
Begin by creating a new project called hello-world
:
turbo init hello-world
This initializes a Rust project with the following structure:
hello-world/ # Your project's root directory.
βββ src/ # The directory of your code.
β βββ lib.rs # The main file for the game.
βββ Cargo.toml # Rust project manifest.
βββ turbo.toml # Turbo configuration.
Run the Game
Next, run your game with the following command:
turbo run -w hello-world
Give it a moment to compile. Once it completes, a game window will appear.
By default, a new Turbo game will have some boilerplate code that displays, "Hello, world!!!". So our work here is done. Just kidding. We're going to jazz it up a bit. Continue on to the next step.
Update the Text
Leave the turbo run
command running. Open the hello-world
project in your preferred editor. View hello-world/src/lib.rs
. Inside, you should see something like this:
turbo::go!({
text!("Hello, world!!!");
});
Modify the text, save the file, and check out your game window.
turbo::go!({
text!("Hello, world!!!")
text!("Yuuurrr!");
});
It should now display your updated text.
Add Some Style
The text!
macro has several optional parameters you can experiment with:
turbo::go!({
text!(
"Let's gooo!", // Text to display
font = "large" // Font ("small", "medium", and "large" are available by default)
color = 0xff00ffff, // Text color (in hexadecimal)
x = 32, // Starting x position of the text
y = 48, // Starting y position of the text
);
});
Check out the Text docs to see more examples of how to work with text in Turbo.
Conclusion
You've taken your first step into the world of Turbo β initialized a project, launched a live-updating game window, and styled your very first in-game message. It might not seem like much, but this is how every great game begins: with one line of code and the will to make something fun.
Next Steps
From here, you're ready to:
- Build your first interactive game
- Explore sprites, input, and sound
- Learn how game state works in Turbo
Your very own Turbo legend has begun β let's keep going.