Docs.rs
  • bevy_mod_observable_timer-0.3.0
    • bevy_mod_observable_timer 0.3.0
    • Permalink
    • Docs.rs crate page
    • MIT OR Apache-2.0
    • Links
    • Repository
    • crates.io
    • Source
    • Owners
    • grind086
    • Dependencies
      • bevy ^0.16.0 normal
      • bevy ^0.16.0 dev
    • Versions
    • 100% of the crate is documented
  • Platform
    • i686-pc-windows-msvc
    • i686-unknown-linux-gnu
    • x86_64-apple-darwin
    • x86_64-pc-windows-msvc
    • x86_64-unknown-linux-gnu
  • Feature flags
  • docs.rs
    • About docs.rs
    • Privacy policy
  • Rust
    • Rust website
    • The Book
    • Standard Library API Reference
    • Rust by Example
    • The Cargo Guide
    • Clippy Documentation

Crate bevy_mod_observable_timer

bevy_mod_observable_timer0.3.0

  • All Items

Sections

  • bevy_mod_observable_timer
    • Basic Example
    • Compatibility
    • License

Crate Items

  • Structs
  • Enums

Crates

  • bevy_mod_observable_timer

Crate bevy_mod_observable_timer

Source
Expand description

§bevy_mod_observable_timer

License Crates.io Downloads Docs

This crate provides an observer-based timer system for bevy entities. Any entity may have an ObservableTimer component attached to it, which will produce observable lifetime cycle triggers.

  • TimerStarted is triggered immediately after inserting a new ObservableTimer (including when overwriting an old one).
  • TimerFinished is triggered after each elapsed interval.
  • TimerStopped is triggered when the ObservableTimer component is removed/despawned.

When a timer finishes it will automatically perform some behavior. By default this is despawning its attached entity. See TimerFinishBehavior for more information.

§Basic Example

use bevy::{log::LogPlugin, prelude::*};
use bevy_mod_observable_timer::*;

fn main() {
    App::new()
        .add_plugins((
            MinimalPlugins,
            LogPlugin::default(),
            ObservableTimerPlugin::default(),
        ))
        .add_systems(Startup, startup)
        .run();
}

fn startup(mut commands: Commands) {
    commands
        .spawn(ObservableTimer::from_seconds(1.0, TimerMode::Repeating))
        .observe(|_: Trigger<TimerStarted>| {
            info!("Timer started");
        })
        .observe(
            |trigger: Trigger<TimerFinished>, mut count: Local<usize>, mut commands: Commands| {
                *count += 1;
                info!("Timer finished (#{})", *count);

                if *count == 5 {
                    commands.entity(trigger.target()).despawn();
                }
            },
        )
        .observe(
            |_: Trigger<TimerStopped>, mut app_exit: EventWriter<AppExit>| {
                info!("Timer stopped");
                app_exit.write_default();
            },
        );
}

Output:

Timer started
Timer finished (#1)
Timer finished (#2)
Timer finished (#3)
Timer finished (#4)
Timer finished (#5)
Timer stopped

§Compatibility

bevybevy_mod_observable_timer
0.160.3
0.150.2
0.140.1

§License

Except where noted, all code in this repository is dual-licensed under either:

  • MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
  • Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)

at your option.

Structs§

ObservableTimer
A timer component that triggers observable lifecycle events on its Entity.
ObservableTimerPlugin
This plugin provides functionality for the ObservableTimer component.
ObservableTimerSystems
The SystemSet during which ObservableTimers are updated.
TimerFinished
A timer Event that is triggered when an ObservableTimer finishes.
TimerStarted
A timer Event that is triggered when an ObservableTimer is inserted or spawned.
TimerStopped
A timer Event that is triggered when an ObservableTimer is removed or despawned.

Enums§

TimerFinishBehavior
Describes the behavior that should be taken by an ObservableTimer upon finishing.

Results

Settings
Help
    struct
    bevy_mod_observable_timer::ObservableTimer
    A timer component that triggers observable lifecycle …
    struct
    bevy_mod_observable_timer::ObservableTimerPlugin
    This plugin provides functionality for the ObservableTimer …
    struct
    bevy_mod_observable_timer::ObservableTimerSystems
    The SystemSet during which ObservableTimers are updated.
    extern crate
    bevy_mod_observable_timer
    bevy_mod_observable_timer
    struct field
    bevy_mod_observable_timer::ObservableTimer::timer
    ObservableTimer -> Timer
    The internal Timer.
    struct field
    bevy_mod_observable_timer::ObservableTimer::finish_behavior
    ObservableTimer -> TimerFinishBehavior
    The timer’s finish behavior.
    method
    bevy_mod_observable_timer::ObservableTimer::clone
    &ObservableTimer -> ObservableTimer
    method
    bevy_mod_observable_timer::ObservableTimer::with_finish_behavior
    ObservableTimer, TimerFinishBehavior -> ObservableTimer
    Set the TimerFinishBehavior for this timer.
    method
    bevy_mod_observable_timer::ObservableTimer::deref
    &ObservableTimer -> &Deref::Target
    method
    bevy_mod_observable_timer::ObservableTimer::fmt
    &ObservableTimer, &mut Formatter -> Result
    method
    bevy_mod_observable_timer::ObservableTimer::deref_mut
    &mut ObservableTimer -> &mut Deref::Target
    method
    bevy_mod_observable_timer::ObservableTimer::new
    Duration, TimerMode -> ObservableTimer
    Create a new timer.
    method
    bevy_mod_observable_timer::ObservableTimer::from_seconds
    f32, TimerMode -> ObservableTimer
    Create a new timer from a duration in seconds.
    method
    bevy_mod_observable_timer::ObservableTimer::clone
    &ObservableTimer -> ObservableTimer
    method
    bevy_mod_observable_timer::ObservableTimer::with_finish_behavior
    ObservableTimer, TimerFinishBehavior -> ObservableTimer
    Set the TimerFinishBehavior for this timer.