Skip to content

wireframe example: use FixedUpdate instead of a timer #10104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 7 additions & 20 deletions examples/3d/wireframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@ fn main() {
// You need to add this plugin to enable wireframe rendering
WireframePlugin,
))
.insert_resource(WireframeToggleTimer(Timer::from_seconds(
1.0,
TimerMode::Repeating,
)))
.add_systems(Startup, setup)
.add_systems(Update, toggle_global_wireframe_setting)
.add_systems(FixedUpdate, toggle_global_wireframe_setting)
.insert_resource(FixedTime::new_from_secs(1.0))
.run();
}

Expand Down Expand Up @@ -91,21 +88,11 @@ fn setup(
});
}

/// This timer is used to periodically toggle the wireframe rendering.
#[derive(Resource)]
struct WireframeToggleTimer(Timer);

/// Periodically turns the global wireframe setting on and off, to show the differences between
/// [`Wireframe`], [`NoWireframe`], and just a mesh.
fn toggle_global_wireframe_setting(
time: Res<Time>,
mut timer: ResMut<WireframeToggleTimer>,
mut wireframe_config: ResMut<WireframeConfig>,
) {
if timer.0.tick(time.delta()).just_finished() {
// The global wireframe config enables drawing of wireframes on every mesh,
// except those with `NoWireframe`. Meshes with `Wireframe` will always have a wireframe,
// regardless of the global configuration.
wireframe_config.global = !wireframe_config.global;
}
fn toggle_global_wireframe_setting(mut wireframe_config: ResMut<WireframeConfig>) {
// The global wireframe config enables drawing of wireframes on every mesh,
// except those with `NoWireframe`. Meshes with `Wireframe` will always have a wireframe,
// regardless of the global configuration.
wireframe_config.global = !wireframe_config.global;
}