3 unstable releases
Uses new Rust 2024
| 0.2.0 | Oct 1, 2025 |
|---|---|
| 0.2.0-rc.0 | Sep 15, 2025 |
| 0.1.0 | May 13, 2025 |
#1328 in Game dev
25 downloads per month
Used in bevy_text_edit
22KB
94 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
~20–33MB
~541K SLoC