rscenes 1.4.1

Scenes manager for Raylib.
Documentation
rscenes-1.4.1 has been yanked.

rscenes

Rscene is a scene manager for Raylib.

Installation

cargo add rscenes

Sample

You don’t need to include raylib, the following line alone is enough:

use rscene::prelude::*

Then, in your function, instantiate the builder and the manager:

let mut builder = raylib::init();
builder.title("my-game"); // this sets WM_CLASS
let font: Option<Font> = None;
let mut manager = SceneManager::new(builder, font);
manager.config(|handle, thread, font| {
    // Here you set the window title, otherwise it’s gonna be the same as
    // the WM_CLASS.
    handle.set_window_title(thread, "My Game");
    // You can call any handle method you need here.
    // For instance, the default framerate is 60fps, you can change it here:
    handle.set_target_fps(30);
    // Or load a font:
    font.insert(handle.load_font(thread, "font.ttf").unwrap());
});
manager.add_first_scene(Box::new(MyScene::default()));
manager.start()?;

The scene should be implemented like:

#[derive(Debug, Default)]
struct MyScene;

impl Scene<Option<Font>> for MyScene {
    fn init(&mut self, handle: &mut RaylibHandle, thread: &RaylibThread) -> anyhow::Result<()> {
        // Perform any initialisation you need here
        Ok(())
    }

    fn update(
        &mut self,
        (handle, thread): (&mut RaylibHandle, &RaylibThread),
        dt: f32,
        resources: &mut Option<Font>,
    ) -> anyhow::Result<State<Option<Font>>> {
        // Per frame update:
        // dt is time since last frame in seconds.
        Ok(State::Keep)
    }

    fn draw(
        &mut self,
        handle: &mut RaylibDrawHandle,
        screen: Rectangle,
        resources: &Option<Font>,
    ) -> anyhow::Result<()> {
        // Instantiate your RaylibMode2D or RaylibMode3D and draw here.
        // This is rendered once per frame.
        Ok(())
    }
}

The main resources are:

Everything else is exposed from raylib::prelude.

Features

Enabling ecs feature, rscenes::prelude::* is gonna bring all resources from hecs, like Entity, Query*, Ref*, With, and World.

rscenes = {version = "*", features = ["ecs"]}

License

License: BSD-3-Clause