[−][src]Trait yagl::Game
Trait describing the behavior of a game.
This is the main entry point in interacting with yagl.
To create a game with yagl, you just need to implement this trait and return an instance of it in the closure you pass to yagl::run.
Required methods
fn update(&mut self, actx: &mut AppContext) -> Result<()>
Called to check if the game should be updated
fn render(&mut self, rctx: &mut RenderContext) -> Result<()>
Called when drawing on the screen is requested
The RenderContext can retrieve the AppContext if needed with
the actx()
method.
To render something on the screen, the render
method
on the RenderContext should be called exactly once.
If called more than once, it may erase the previous draw
Provided methods
fn options(&self) -> Options
This method is called exactly once on start
fn resize(
&mut self,
actx: &mut AppContext,
width: u32,
height: u32
) -> Result<()>
&mut self,
actx: &mut AppContext,
width: u32,
height: u32
) -> Result<()>
Called when the window is resized
fn char(&mut self, actx: &mut AppContext, ch: char) -> Result<()>
Called on character input
fn key_pressed(&mut self, actx: &mut AppContext, key: Key) -> Result<()>
Called to notify the game that a key was pressed.
The default behavior of this method is to exit when Escape is pressed
NOTE, not all keys may be recognized. If it isn't, this method will not get called for those keys.
In the future, there should be a separate 'key_scancode_*' method so that even if the key is not recognized, the raw scancode can be passed to the client to process.
fn key_released(&mut self, actx: &mut AppContext, key: Key) -> Result<()>
Called to notify the game that a key was released.
NOTE, not all keys may be recognized. If it isn't, this method will not get called for those keys.
In the future, there should be a separate 'key_scancode_*' method so that even if the key is not recognized, the raw scancode can be passed to the client to process.
fn mouse_moved(&mut self, actx: &mut AppContext, pos: [f32; 2]) -> Result<()>
fn mouse_button_pressed(
&mut self,
actx: &mut AppContext,
pos: [f32; 2],
button: MouseButton
) -> Result<()>
&mut self,
actx: &mut AppContext,
pos: [f32; 2],
button: MouseButton
) -> Result<()>
fn mouse_button_released(
&mut self,
actx: &mut AppContext,
pos: [f32; 2],
button: MouseButton
) -> Result<()>
&mut self,
actx: &mut AppContext,
pos: [f32; 2],
button: MouseButton
) -> Result<()>
fn scroll(
&mut self,
actx: &mut AppContext,
pos: [f32; 2],
delta: [f32; 2]
) -> Result<()>
&mut self,
actx: &mut AppContext,
pos: [f32; 2],
delta: [f32; 2]
) -> Result<()>
Fired when a scroll event is received. This could be triggered by a mouse wheel or trackpad. The delta of [horizontal, vertical] is provided.
fn gamepad_connected(
&mut self,
actx: &mut AppContext,
dev: DeviceId
) -> Result<()>
&mut self,
actx: &mut AppContext,
dev: DeviceId
) -> Result<()>
fn gamepad_disconnected(
&mut self,
actx: &mut AppContext,
dev: DeviceId
) -> Result<()>
&mut self,
actx: &mut AppContext,
dev: DeviceId
) -> Result<()>
fn gamepad_button_pressed(
&mut self,
actx: &mut AppContext,
dev: DeviceId,
button: GamepadButton
) -> Result<()>
&mut self,
actx: &mut AppContext,
dev: DeviceId,
button: GamepadButton
) -> Result<()>
A button on a gamepad was pressed
fn gamepad_button_released(
&mut self,
actx: &mut AppContext,
dev: DeviceId,
button: GamepadButton
) -> Result<()>
&mut self,
actx: &mut AppContext,
dev: DeviceId,
button: GamepadButton
) -> Result<()>
A button on a gamepad was released
fn gamepad_axis_changed(
&mut self,
actx: &mut AppContext,
dev: DeviceId,
axis: Axis,
value: f32
) -> Result<()>
&mut self,
actx: &mut AppContext,
dev: DeviceId,
axis: Axis,
value: f32
) -> Result<()>
An axis on a gamepad was changed