10 个不稳定版本 (3 个破坏性更新)
0.4.2 | 2024年1月7日 |
---|---|
0.4.1 | 2023年12月27日 |
0.3.4 | 2023年12月23日 |
0.2.0 | 2023年12月19日 |
0.1.0 | 2023年12月19日 |
#907 in 游戏开发
29KB
606 行
游戏工具
简单游戏工具
用法
Cargo
在您的 Cargo.toml 文件中添加
simple-game-utils = { version = "0.4.2", features = ["controller"] }
代码
计时
此程序运行1秒钟后退出。
//track passage of time
let mut timing = Timing::new(240); //UPS
//triggers after specified time has passed
let mut timer = Timer::new(1.0);
loop {
//automatically updates based on how much time has passed since the last call
timing.update();
//returns true if time has run out
if timer.update(timing) {
break;
}
}
声音
需要
sound
功能
let mut engine = AudioEngine::new().unwrap();
let mut sound = engine.load_from_bytes(&some_sound_bytes, duration).unwrap();
sound.play();
loop {
timing.update();
sound.update(&timing);
}
控制器
需要
controller
或controller_xinput
功能
// This will work whether or not there's a controller plugged in
let mut controller = GameController::new().expect("Unable to init controller lib");
loop {
controller.update();
if controller.direction.up {
println!("DPad UP pressed");
}
}
首选项
需要
prefs
功能
struct Settings {
user: String,
theme: usize
}
let prefs: AppPrefs<Settings> = AppPrefs::new("com","example","readme", || Settings::default()).unwrap();
println!("{}", prefs.data.user);
prefs.data.user = String::new("New");
prefs.save();
特性
默认特性:
prefs
,sound
,serde
prefs
简单的结构体存储
controller
非常基本的控制器支持
- 不支持选择控制器
不能与
controllerxinput
一起使用
controller_xinput
使用 XInput 控制器(仅限 Windows)
不能与
controller
一起使用
sound
基本音效或音乐播放
serde
为某些结构体和枚举添加序列化
依赖项
~0.5–31MB
~459K SLoC