From 9a3d5b4a98fef6366af5251e375f18e5ea569645 Mon Sep 17 00:00:00 2001 From: Mike Hsu Date: Mon, 1 Mar 2021 21:55:11 -0800 Subject: [PATCH 1/4] change to a fixed timestep --- examples/game/breakout.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/examples/game/breakout.rs b/examples/game/breakout.rs index 23169838dc33b..6c3882334e7c2 100644 --- a/examples/game/breakout.rs +++ b/examples/game/breakout.rs @@ -1,23 +1,35 @@ use bevy::{ + core::{FixedTimestep}, prelude::*, render::pass::ClearColor, sprite::collide_aabb::{collide, Collision}, }; /// An implementation of the classic game "Breakout" +const TIME_STEP: f32 = 1.0 / 60.0; fn main() { App::build() .add_plugins(DefaultPlugins) .insert_resource(Scoreboard { score: 0 }) .insert_resource(ClearColor(Color::rgb(0.9, 0.9, 0.9))) .add_startup_system(setup.system()) - .add_system(paddle_movement_system.system()) - .add_system(ball_collision_system.system()) - .add_system(ball_movement_system.system()) + .add_stage( + FixedUpdateStage, + SystemStage::parallel() + .with_run_criteria( + FixedTimestep::step(TIME_STEP as f64) + ) + .with_system(paddle_movement_system.system()) + .with_system(ball_collision_system.system()) + .with_system(ball_movement_system.system()), + ) .add_system(scoreboard_system.system()) .run(); } +#[derive(Debug, Hash, PartialEq, Eq, Clone, StageLabel)] +struct FixedUpdateStage; + struct Paddle { speed: f32, } @@ -175,7 +187,6 @@ fn setup( } fn paddle_movement_system( - time: Res