Rscene is a scene manager for Raylib.
sh
cargo add rscenes
You don’t need to include raylib
, the following line alone is enough:
rust
use rscene.prelude::*
Then, in your function, instantiate the builder and the manager:
rust
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, handle).unwrap());
});
manager.add_first_scene(Box::new(MyScene::default()));
manager.start()?;
The scene should be implemented like:
```rust
struct MyScene;
impl Scene
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:
Scene
SceneManager
State
colors
raylib
(Raylib itself)Everything else is exposed from
raylib::prelude
.
License: BSD-3-Clause