Created
August 23, 2021 21:18
-
-
Save payload/9a329eaf18725d54885c93da7f6f4426 to your computer and use it in GitHub Desktop.
rotating 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
use bevy::prelude::*; | |
fn main() { | |
App::new() | |
.add_plugins(DefaultPlugins) | |
.add_startup_system(setup) | |
.add_system(update) | |
.run(); | |
} | |
fn setup( | |
mut commands: Commands, | |
asset_server: Res<AssetServer>, | |
mut materials: ResMut<Assets<ColorMaterial>>, | |
) { | |
let texture_handle = asset_server.load("branding/icon.png"); | |
commands.spawn_bundle(OrthographicCameraBundle::new_2d()); | |
commands.spawn_bundle(SpriteBundle { | |
material: materials.add(texture_handle.into()), | |
..Default::default() | |
}); | |
} | |
fn update(mut query: Query<&mut Transform, With<Sprite>>, mut angle: Local<f32>) { | |
for mut transform in query.iter_mut() { | |
*angle += 0.01; | |
transform.rotation = Quat::from_rotation_z(*angle); | |
println!("{}", *angle); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment