Piston-Window is a convenience window wrapper for the Piston game engine.
It is completely independent of the piston core and the other libraries,
so no Piston library requires you to use Piston-Window.
Piston-Window is designed for only one purpose: Convenience.
- Reexports everything you need to write 2D interactive applications
.draw_2d
for drawing 2D, and.draw_3d
for drawing 3D- Uses Gfx to work with 3D libraries in the Piston ecosystem
- A smart design to pass around the window and application state
extern crate piston_window;
use piston_window::*;
fn main() {
let window: PistonWindow = WindowSettings::new("Hello Piston!", [640, 480])
.exit_on_esc(true).into();
for e in window {
e.draw_2d(|_c, g| {
clear([0.5, 1.0, 0.5, 1.0], g);
});
}
}
PistonWindow
implements AdvancedWindow
, Iterator
, Window
and GenericEvent
.
The iterator emits new PistonWindow
objects, that contain the event from the game loop.
You can swap the application state with .app
method.
PistonWindow
also supports nested game loops, so you can have one inside another.
for e in window {
if let Some(button) = e.press_args() {
let intro = e.app(start_intro());
for e in intro {
...
}
}
}