Crates.io | bevy_auto_timer |
lib.rs | bevy_auto_timer |
version | 0.1.0 |
created_at | 2025-05-13 07:13:23.722898+00 |
updated_at | 2025-05-13 07:13:23.722898+00 |
description | Bevy plugin for convenent timer |
homepage | |
repository | https://gitlab.com/kimtinh/bevy_auto_timer |
max_upload_size | |
id | 1671479 |
size | 62,956 |
A convenient timer which ticks automatically.
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!");
}
Please see LICENSE.
bevy | bevy_auto_timer |
---|---|
0.16 | 0.1 |