Skip to content

Hello, World!

Your very own Turbo legend is about to unfold

Turbo game window with the text "Hello, world!!!"

Overview

Walkthrough

Initialize the Project

Begin by creating a new project called hello-world:

Terminal
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:

Terminal
turbo run -w hello-world

Give it a moment to compile. Once it completes, a game window will appear.

Turbo game window with the text "Hello, world!!!"

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:

hello-world/src/lib.rs
use turbo::*;
 
#[turbo::game]
struct GameState {
    // Add fields here
}
impl GameState {
    pub fn new() -> Self {
        // initialize your game state
        Self { }
    }
    pub fn update(&mut self) {
        // This is where your main game loop code goes
        // The stuff in this block will run ~60x per sec
        text!("Hello, world!!!");
    }
}

Modify the text, save the file, and check out your game window.

hello-world/src/lib.rs
use turbo::*;
 
#[turbo::game]
struct GameState {
    // Add fields here
}
impl GameState {
    pub fn new() -> Self {
        // initialize your game state
        Self { }
    }
    pub fn update(&mut self) { 
        // This is where your main game loop code goes
        // The stuff in this block will run ~60x per sec
        text!("Hello, world!!!") 
        text!("Yuuurrr!"); 
    } 
}

It should now display your updated text.

Turbo game window with the text "yuuurrr!!!"

Add Some Style

The text! macro has several optional parameters you can experiment with:

hello-world/src/lib.rs
use turbo::*;
 
#[turbo::game]
struct GameState {
    // Add fields here
}
impl GameState {
    pub fn new() -> Self {
        // initialize your game state
        Self { }
    }
    pub fn update(&mut self) { 
        // This is where your main game loop code goes
        // The stuff in this block will run ~60x per sec
        text!("Yuuurrr!"); 
        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.