1 unstable release
Uses new Rust 2024
new 0.1.0 | May 13, 2025 |
---|
#897 in Game dev
20KB
92 lines
A convenient timer which ticks automatically.
Quickstart
use bevy::prelude::*;
use bevy_auto_timer::{AutoTimer, AutoTimerFinished, AutoTimerPlugin, AutoTimerPluginAnyState};
#[derive(States, Debug, Clone, Copy, Eq, PartialEq, Hash, Default)]
enum GameState {
#[default]
Menu,
InGame,
EndGame,
}
fn main() {
let mut app = App::new().add_plugins(DefaultPlugins).init_state::<GameState>();
// Add this plugin and specify which state it will run in
app.add_plugins(AutoTimerPlugin::new(vec![GameState::InGame, GameState::EndGame]));
// or you can use `AutoTimerPluginAnyState` for running on any states.
// app.add_plugins(AutoTimerPluginAnyState::any());
app.add_systems(Startup, setup).run();
}
fn setup(mut commands: Commands, mut next_state: ResMut<NextState<GameState>>) {
// Spawn timer as a component
commands
.spawn(AutoTimer::from_seconds(1., TimerMode::Repeating))
.observe(timeout); // observe event `AutoTimerFinished`
next_state.set(GameState::InGame);
}
fn timeout(_: Trigger<AutoTimerFinished>) {
info!("Timer finished!");
}
License
Please see LICENSE.
Compatible Bevy Versions
bevy | bevy_auto_timer |
---|---|
0.16 | 0.1 |
Dependencies
~18–24MB
~415K SLoC