Last active
January 6, 2023 17:54
-
-
Save ark0f/bd2cf93484a1437d20d1d0b9b2533d7a to your computer and use it in GitHub Desktop.
DOES NOT WARK BECAUSE OF FLICKERING; Top left origin with pixel-perfect scaling in 2D in Bevy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn setup(mut commands: Commands) { | |
let mut camera = OrthographicCameraBundle::new_2d(); | |
camera.orthographic_projection.window_origin = WindowOrigin::BottomLeft; | |
camera.orthographic_projection.scaling_mode = ScalingMode::WindowSize; | |
commands.spawn(camera); | |
} | |
fn top_left_origin( | |
windows: Res<Windows>, | |
mut transforms: Query<&mut Transform, (Changed<Transform>, Without<Camera>)>, | |
) { | |
let window = windows.get_primary().unwrap(); | |
for mut transform in transforms.iter_mut() { | |
transform.translation.y = window.height() - transform.translation.y; | |
} | |
} | |
fn main() { | |
App::build() | |
.add_plugins(DefaultPlugins) | |
.add_startup_system(setup.system()) | |
.add_system_to_stage(CoreStage::PostUpdate, top_left_origin.system()) | |
.run(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment