use bevy::prelude::*; use bevy_inspector_egui::{bevy_egui::EguiPlugin, quick::WorldInspectorPlugin}; use virtual_joystick::*; fn main() { App::new() .add_plugins(DefaultPlugins) .add_plugins(EguiPlugin::default()) .add_plugins(WorldInspectorPlugin::new()) .add_plugins(VirtualJoystickPlugin::::default()) .add_systems(Startup, create_scene) .add_systems(Update, update_joystick) .run(); } #[derive(Component)] /// Player with velocity struct Player(pub f32); fn create_scene(mut cmd: Commands, asset_server: Res) { cmd.spawn((Camera2d, Transform::from_xyz(0., 0., 5.0))); // Fake Player cmd.spawn(Sprite { image: asset_server.load("Knob.png"), color: Color::srgb(0.5, 0.0, 0.5), //Purple custom_size: Some(Vec2::new(50., 50.)), ..default() }) .insert(Player(50.)); // Spawn Virtual Joystick at horizontal center using helper function create_joystick( &mut cmd, "UniqueJoystick".to_string(), asset_server.load("Knob.png"), asset_server.load("Outline.png"), None, None, Some(Color::srgba(1.0, 0.27, 0.0, 0.3)), Vec2::new(75., 75.), Vec2::new(150., 150.), Node { width: Val::Percent(100.), height: Val::Percent(100.), position_type: PositionType::Absolute, left: Val::Percent(0.), bottom: Val::Percent(0.), ..default() }, JoystickFloating, NoAction, ); } fn update_joystick( mut reader: MessageReader>, player: Single<(&mut Transform, &Player)>, time_step: Res