9个版本 (5个重大更新)
0.7.0 | 2022年12月23日 |
---|---|
0.5.4 | 2022年11月27日 |
0.4.0 | 2021年4月4日 |
0.3.0 | 2021年3月27日 |
0.1.0 | 2020年7月6日 |
#539 in 图像
在2个crate中使用(通过pixel_engine)
62KB
1.5K SLoC
pixel_engine
用Rust编写的旧PixelGameEngine(by OneLoneCoder)的复制品。这个crate分为3个crate
pixel_engine_backend
这提供wgpu的包装器。它处理贴图的绘制和主屏幕
pixel_engine_draw
这个crate提供处理绘制的特质。你只需要实现一个特质(SmartDrawing特质)和其他特质只是超特质,所以你可以免费获得它们
pixel_engine
这是项目的核心,是主要库,旨在供用户使用。它提供Engine结构体
如何使用
在examples
文件夹中有许多示例。你只需要运行cargo run --bin=<NAME>
,或者访问(https://maix.me)https://maix.me/以获取示例代码列表。
extern crate pixel_engine as px;
use px::traits::*;
fn main() {
px::launch(async move { // the launch function is just a utility function to block on async, even on the web
let game = px::EngineWrapper::new("Lines".to_owned(), (25, 25, 20));
let mut start = (0, 0);
let mut end = (5i32, 5i32);
game.run(move |game: &mut engine::Engine| {
// Drawing to the screen:
game.clear([0, 0, 0].into());
game.draw_line(
start,
end,
[1.0, 1.0, 1.0].into(),
);
game.draw(start, [0, 255, 0].into());
game.draw(end, [255, 0, 0].into());
some_failible_function()?; // You can return errors, but it will crash the program and print the error message
// Handling inputs
game.get_key(px::inputs::Keycodes::Escape).any() {
return Ok(false); // Returning Ok(false) is the only way to do a clean shutdown
}
Ok(true) // Continue to next frame
});
});
}
这是line
示例的简化代码。有一些示例实际上并不太有用(如input.rs
)。它们在这里是为了确保我不会破坏东西。
依赖项
~13–19MB
~72K SLoC