[−][src]Crate ggez
What is this?
ggez is a Rust library to create a Good Game Easily.
More specifically, ggez is a lightweight game framework for making 2D games with minimum friction. It aims to implement an API based on (a Rustified version of) the LÖVE game framework. This means it contains basic and portable 2D drawing, sound, resource loading and event handling.
For a fuller outline, see the README.md
Usage
ggez consists of three main parts: A Context
object
which contains all the state required to interface with the computer's
hardware, an EventHandler
trait that the
user implements to register callbacks for events, and various sub-modules such as
graphics
and audio
that provide
the functionality to actually get stuff done.
The general pattern is to create a struct holding your game's data which implements
the EventHandler
trait. Create a ContextBuilder
object with configuration settings, use it to create a new Context
object,
and then call event::run()
with the Context
and an instance of
your EventHandler
to run your game's main loop.
Basic Project Template
use ggez::{Context, ContextBuilder, GameResult}; use ggez::event::{self, EventHandler}; use ggez::graphics; fn main() { // Make a Context and an EventLoop. let (mut ctx, mut event_loop) = ContextBuilder::new("game_name", "author_name") .build() .unwrap(); // Create an instance of your event handler. // Usually, you should provide it with the Context object // so it can load resources like images during setup. let mut my_game = MyGame::new(&mut ctx); // Run! match event::run(&mut ctx, &mut event_loop, &mut my_game) { Ok(_) => println!("Exited cleanly."), Err(e) => println!("Error occured: {}", e) } } struct MyGame { // Your state here... } impl MyGame { pub fn new(_ctx: &mut Context) -> MyGame { // Load/create resources here: images, fonts, sounds, etc. MyGame { } } } impl EventHandler for MyGame { fn update(&mut self, _ctx: &mut Context) -> GameResult<()> { // Update code here... } fn draw(&mut self, ctx: &mut Context) -> GameResult<()> { graphics::clear(ctx, graphics::WHITE); // Draw code here... graphics::present(ctx) } }
Re-exports
pub extern crate mint; |
pub extern crate nalgebra; |
pub use crate::error::*; |
Modules
audio | Provides an interface to output sound to the user's speakers. |
conf | The |
error | Error types and conversion functions. |
event | The |
filesystem | A cross-platform interface to the filesystem. |
graphics | The |
input | Input handling modules for keyboard, mouse and gamepad. |
timer | Timing and measurement functions. |
Structs
Context | A |
ContextBuilder | A builder object for creating a |