ggez/lib.rs
1//! [](http://ggez.rs/)
2//!
3//! # What is this?
4//!
5//! 
6//! [](https://docs.rs/ggez)
7//! [](https://github.com/ggez/ggez/blob/master/LICENSE)
8//! [](https://crates.io/crates/ggez)
9//! [](https://crates.io/crates/ggez)
10//! [](https://discord.gg/48VycPe2ZX)
11//!
12//! ggez is a Rust library to create a Good Game Easily.
13//!
14//! More specifically, ggez is a lightweight cross-platform game framework
15//! for making 2D games with minimum friction. It aims to implement an
16//! API based on (a Rustified version of) the [LÖVE](https://love2d.org/)
17//! game framework. This means it contains basic and portable 2D
18//! drawing, sound, resource loading and event handling, but finer details
19//! and performance characteristics may be different than LÖVE.
20//!
21//! ggez is not meant to be everything to everyone, but rather a good
22//! base upon which to build. Thus it takes a fairly
23//! batteries-included approach without needing a million additions
24//! and plugins for everything imaginable, but also does not dictate
25//! higher-level functionality such as physics engine or entity
26//! component system. Instead the goal is to allow you to use
27//! whichever libraries you want to provide these functions, or build
28//! your own libraries atop ggez.
29//!
30//! ## Features
31//!
32//! * Filesystem abstraction that lets you load resources from folders or zip files
33//! * Hardware-accelerated 2D rendering built on the `wgpu` graphics API
34//! * Loading and playing .ogg, .wav and .flac files via the `rodio` crate
35//! * TTF font rendering with `glyph_brush`.
36//! * Interface for handling keyboard and mouse events easily through callbacks
37//! * Config file for defining engine and game settings
38//! * Easy timing and FPS measurement functions.
39//! * Math library integration with `mint`.
40//! * Some more advanced graphics options: shaders, instanced draws and render targets
41//!
42//! ### Supported platforms
43//!
44//! * Fully supported: Windows, Linux
45//! * Not officially supported but might work anyway: Mac
46//!
47//! For details, see [docs/BuildingForEveryPlatform.md](https://github.com/ggez/ggez/blob/master/docs/BuildingForEveryPlatform.md)
48//!
49//! If you want to run ggez on Android, iOS or the web using WebAssembly take a look at [good-web-game](https://github.com/ggez/good-web-game).
50//!
51//! ## Who's using ggez?
52//!
53//! Check out the [projects list!](https://github.com/ggez/ggez/blob/master/docs/Projects.md)
54//!
55//! ## Usage
56//!
57//! ggez requires rustc >= 1.42 and is distributed on
58//! crates.io. To include it in your project, just add the dependency
59//! line to your `Cargo.toml` file:
60//!
61//! ```text
62//! ggez = "0.10.0"
63//! ```
64//!
65//! ggez consists of three main parts: A `Context` object which
66//! contains all the state required to interface with the computer's
67//! hardware, an `EventHandler` trait that the user implements to
68//! register callbacks for events, and various sub-modules such as
69//! `graphics` and `audio` that provide the functionality to actually
70//! get stuff done. The general pattern is to create a struct holding
71//! your game's data which implements the `EventHandler` trait.
72//! Create a new `Context` object with default objects from a `ContextBuilder`
73//! or `Conf` object, and then call `event::run()` with
74//! the `Context` and an instance of your `EventHandler` to run your game's
75//! main loop.
76//!
77//! See the [API docs](https://docs.rs/ggez/) for full documentation, or the [examples](https://github.com/ggez/ggez/tree/master/examples) directory for a number of commented examples of varying complexity. Most examples show off
78//! a single feature of ggez, while `astroblasto` and `snake` are small but complete games.
79//!
80//! ## Getting started
81//!
82//! For a quick tutorial on ggez, see the [Hello ggez](https://github.com/ggez/ggez/blob/master/docs/guides/HelloGgez.md) guide in the `docs/` directory.
83//!
84//! ## Examples
85//!
86//! See the `examples/` directory in the source. Most examples show off
87//! a single feature of ggez, while `astroblasto` is a small but
88//! complete Asteroids-like game.
89//!
90//! To run the examples, just check out the source and execute `cargo run --example`
91//! in the root directory:
92//!
93//! ```text
94//! git clone https://github.com/ggez/ggez.git
95//! cd ggez
96//! cargo run --example 05_astroblasto
97//! ```
98//!
99//! If this doesn't work, see the
100//! [FAQ](https://github.com/ggez/ggez/blob/master/docs/FAQ.md) for solutions
101//! to common problems.
102//!
103//! ### Basic Project Template
104//!
105//! ```rust,no_run
106//! use ggez::{Context, ContextBuilder, GameResult};
107//! use ggez::graphics::{self, Color};
108//! use ggez::event::{self, EventHandler};
109//!
110//! fn main() {
111//! // Make a Context.
112//! let (mut ctx, event_loop) = ContextBuilder::new("my_game", "Cool Game Author")
113//! .build()
114//! .expect("aieee, could not create ggez context!");
115//!
116//! // Create an instance of your event handler.
117//! // Usually, you should provide it with the Context object to
118//! // use when setting your game up.
119//! let my_game = MyGame::new(&mut ctx);
120//!
121//! // Run!
122//! event::run(ctx, event_loop, my_game);
123//! }
124//!
125//! struct MyGame {
126//! // Your state here...
127//! }
128//!
129//! impl MyGame {
130//! pub fn new(_ctx: &mut Context) -> MyGame {
131//! // Load/create resources such as images here.
132//! MyGame {
133//! // ...
134//! }
135//! }
136//! }
137//!
138//! impl EventHandler for MyGame {
139//! fn update(&mut self, _ctx: &mut Context) -> GameResult {
140//! // Update code here...
141//! Ok(())
142//! }
143//!
144//! fn draw(&mut self, ctx: &mut Context) -> GameResult {
145//! let mut canvas = graphics::Canvas::from_frame(ctx, Color::WHITE);
146//! // Draw code here...
147//! canvas.finish(ctx)
148//! }
149//! }
150//! ```
151//!
152//! ## Implementation details
153//!
154//! ggez is built upon `winit` for windowing and events, `rodio` for
155//! sound, and a 2D drawing engine implemented with `wgpu`. It is entirely
156//! thread-safe (though platform constraints mean the event-handling loop
157//! and drawing must be done in the main thread), and portable to Windows
158//! and Linux.
159//!
160//! ggez is pure Rust™.
161//!
162//! ## Help!
163//!
164//! Sources of information:
165//!
166//! * The [FAQ](https://github.com/ggez/ggez/blob/master/docs/FAQ.md) has answers to common questions and problems.
167//! * The [API docs](https://docs.rs/ggez/), a lot of design stuff is explained there.
168//! * Check out the [examples](https://github.com/ggez/ggez/tree/master/examples).
169//!
170//! If you still have problems or questions, feel free to ask! Easiest ways are:
171//!
172//! * Open an issue on [the Github issue tracker](https://github.com/ggez/ggez/issues)
173//! * Say hi on [our new Discord server](https://discord.gg/48VycPe2ZX)
174//! * Or ask the wise people on the [unofficial Rust Discord server](http://bit.ly/rust-community), the [Rust Gamedev server](https://discord.gg/yNtPTb2) or the [good-web-game Discord server](https://discord.gg/jum3Fjek2A)
175//!
176//! License: MIT
177
178#![doc(
179 html_logo_url = "https://raw.githubusercontent.com/ggez/ggez/master/docs/ggez-logo-maroon-logo-only.svg"
180)]
181#![deny(missing_docs)]
182#![deny(missing_debug_implementations)]
183#![deny(unused_results)]
184#![deny(unsafe_code)]
185#![warn(bare_trait_objects)]
186#![warn(missing_copy_implementations)]
187#![allow(clippy::needless_doctest_main)]
188
189#[macro_use]
190extern crate log;
191
192pub use glam;
193pub use mint;
194pub use winit;
195
196pub mod audio;
197pub mod conf;
198pub mod context;
199pub mod error;
200pub mod event;
201pub mod filesystem;
202pub mod graphics;
203pub mod input;
204pub mod timer;
205mod vfs;
206
207pub mod coroutine;
208pub use crate::coroutine::Coroutine;
209
210pub use crate::context::{Context, ContextBuilder};
211pub use crate::error::*;