timed_draw/
timed_draw.rs

1use comfy::*;
2
3simple_game!("Timed Draw Example", update);
4
5fn update(_c: &EngineContext) {
6    clear_background(BLACK);
7
8    const TIME: f32 = 3.0;
9
10    egui::Window::new("Timed Draw Example")
11        .anchor(egui::Align2::CENTER_CENTER, egui::vec2(0.0, -100.0))
12        .collapsible(false)
13        .title_bar(false)
14        .resizable(false)
15        .show(egui(), |ui| {
16            if ui.button("Click me!").clicked() ||
17                is_key_pressed(KeyCode::Space)
18            {
19                draw_mut().timed(TIME, |_c| {
20                    draw_text(
21                        &format!("I will be visible for {} seconds.", TIME),
22                        Vec2::ZERO,
23                        WHITE,
24                        TextAlign::Center,
25                    );
26
27                    draw_sprite(
28                        texture_id("comfy"),
29                        Vec2::ZERO - vec2(0.0, 4.0),
30                        WHITE,
31                        0,
32                        splat(5.0),
33                    );
34                });
35            }
36        });
37}