bevy_auto_timer

Crates.iobevy_auto_timer
lib.rsbevy_auto_timer
version0.1.0
created_at2025-05-13 07:13:23.722898+00
updated_at2025-05-13 07:13:23.722898+00
descriptionBevy plugin for convenent timer
homepage
repositoryhttps://gitlab.com/kimtinh/bevy_auto_timer
max_upload_size
id1671479
size62,956
Trung Do (dothanhtrung)

documentation

README

bevy_auto_timer

crates.io docs.rs dependency status pipeline status

Gitlab Github

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
Commit count: 4

cargo fmt