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. Thus it contains portable 2D drawing, sound, resource loading and event handling.
use ggez::event;
use ggez::graphics::{self, Color};
use ggez::{Context, GameResult};
use ggez::glam::*;
struct MainState {
pos_x: f32,
}
impl MainState {
fn new() -> GameResult<MainState> {
let s = MainState { pos_x: 0.0 };
Ok(s)
}
}
impl event::EventHandler<ggez::GameError> for MainState {
fn update(&mut self, _ctx: &mut Context) -> GameResult {
self.pos_x = self.pos_x % 800.0 + 1.0;
Ok(())
}
fn draw(&mut self, ctx: &mut Context) -> GameResult {
let mut canvas = graphics::Canvas::from_frame(
ctx,
graphics::Color::from([0.1, 0.2, 0.3, 1.0]),
);
let circle = graphics::Mesh::new_circle(
ctx,
graphics::DrawMode::fill(),
Vec2::new(0.0, 0.0),
100.0,
2.0,
Color::WHITE,
)?;
canvas.draw(&circle, Vec2::new(self.pos_x, 380.0));
canvas.finish(ctx)?;
Ok(())
}
}
pub fn main() -> GameResult {
let cb = ggez::ContextBuilder::new("super_simple", "ggez");
let (ctx, event_loop) = cb.build()?;
let state = MainState::new()?;
event::run(ctx, event_loop, state)
}
ggez is not meant to be everything to everyone, but rather a good base upon which to build higher-level systems and a useful tool that lets you immediately get started on projects such as game jams. As such, it provides:
- Filesystem abstraction that lets you load resources from folders or zip files
- Hardware-accelerated rendering engine built on the
wgpu
graphics engine - Playing and loading .ogg, .wav and .flac files via the
rodio
crate - TTF font rendering with
glyph_brush
- Interface for handling keyboard and mouse events easily through callbacks
- Config file for defining engine and game settings
- Easy timing and FPS measurement functions
- Math integration with
mint
, letting you use any vector math library - Some more advanced graphics options: shaders, sprite batches (i.e. instanced drawing) and render targets