Expand description
Primary [PiEngine] trait and functions which drive your application.
This is the core module of the pix-engine crate and is responsible for building and running
any application using it.
EngineBuilder allows you to customize various engine features and, once built, can
run your application which must implement PixEngine::on_update.
§Example
use pix_engine::prelude::*;
struct MyApp;
impl PixEngine for MyApp {
fn on_start(&mut self, s: &mut PixState) -> PixResult<()> {
// Setup App state. `PixState` contains engine specific state and
// utility functions for things like getting mouse coordinates,
// drawing shapes, etc.
s.background(220);
s.font_family(Font::NOTO)?;
s.font_size(16);
Ok(())
}
fn on_update(&mut self, s: &mut PixState) -> PixResult<()> {
// Main render loop. Called as often as possible, or based on `target frame rate`.
if s.mouse_pressed() {
s.fill(color!(0));
} else {
s.fill(color!(255));
}
let m = s.mouse_pos();
s.circle([m.x(), m.y(), 80])?;
Ok(())
}
fn on_stop(&mut self, s: &mut PixState) -> PixResult<()> {
// Teardown any state or resources before exiting.
Ok(())
}
}
fn main() -> PixResult<()> {
let mut app = MyApp;
let mut engine = Engine::builder()
.dimensions(800, 600)
.title("MyApp")
.build()?;
engine.run(&mut app)
}Structs§
- Engine
- The core engine that maintains the render loop, state, drawing functions, event handling, etc.
- Engine
Builder - Builds a
Engineinstance by providing several configration functions.
Traits§
- PixEngine
- Trait for allowing the
Engineto drive your application and send notification of events, passing along a&mut PixStateto allow interacting with theEngine.