6 个版本
0.1.0-alpha.5 | 2023年12月18日 |
---|---|
0.1.0-alpha.4 | 2023年12月16日 |
#2171 in 游戏开发
在 2 crates 中使用
12KB
186 行
magma_winit
该软件包负责初始化和处理 Magma3D 应用程序的窗口。
lib.rs
:
该软件包将 winit
集成到 Magma3D 引擎中。以下是一个基本用法示例
use magma_app::{App, SystemType, World};
use magma_winit::{windows::Windows, WinitModule};
let mut app = App::new();
app.add_module(WinitModule);
// spawn a window before running the app
app.world.get_resource_mut::<Windows>().unwrap().spawn();
app.add_systems(
SystemType::Update,
(vec![], vec![&open_windows, &close_windows]),
);
app.run();
// open a new window every update
fn open_windows(world: &mut World) {
world.get_resource_mut::<Windows>().unwrap().spawn();
}
// close all the windows when 4 have been spawned
fn close_windows(world: &mut World) {
let window_resource = world.get_resource_mut::<Windows>().unwrap();
if window_resource.windows.len() == 4 {
for i in 0..4 {
window_resource.despawn(i);
}
}
}
依赖关系
~3–20MB
~252K SLoC