From fc23aab92102a9ebb7724a264bd91478ce3e7da4 Mon Sep 17 00:00:00 2001 From: Jeremy Metz Date: Sun, 29 Dec 2024 23:52:14 +0100 Subject: [PATCH] feat: bevy templates upgrade to bevy 0.15 (#428) * feat: Minimal working upgrade to bevy 0.15 * feat: Updated minimal bevy app to 0.15 * feat: Updated demo app readme to acknowledge source --- templates/apps/bevy-demo/Cargo.toml.hbs | 3 ++- templates/apps/bevy-demo/README.md | 4 +--- templates/apps/bevy-demo/src/lib.rs.hbs | 25 +++++++++++++------------ templates/apps/bevy/src/lib.rs.hbs | 6 +++--- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/templates/apps/bevy-demo/Cargo.toml.hbs b/templates/apps/bevy-demo/Cargo.toml.hbs index 47a89cb1..fdbe5082 100644 --- a/templates/apps/bevy-demo/Cargo.toml.hbs +++ b/templates/apps/bevy-demo/Cargo.toml.hbs @@ -15,7 +15,7 @@ name = "{{app.name}}-desktop" path = "gen/bin/desktop.rs" [dependencies] -bevy = { version = "0.14", default-features = false, features = [ +bevy = { version = "0.15", default-features = false, features = [ "animation", "bevy_asset", "bevy_audio", @@ -24,6 +24,7 @@ bevy = { version = "0.14", default-features = false, features = [ "bevy_gilrs", "bevy_scene", "bevy_winit", + "bevy_window", "bevy_core_pipeline", "bevy_pbr", "bevy_gltf", diff --git a/templates/apps/bevy-demo/README.md b/templates/apps/bevy-demo/README.md index af099828..f5a3d060 100644 --- a/templates/apps/bevy-demo/README.md +++ b/templates/apps/bevy-demo/README.md @@ -1,7 +1,5 @@ # bevy-demo -This is just the [Bevy breakout example](https://github.com/bevyengine/bevy/blob/main/examples/games/breakout.rs) with a `#[mobile_entry_point]` attribute on `main`, which generates all the boilerplate `extern` functions for mobile. +This is a modified version of [Niklas Eiker's Bevy Game Template](https://github.com/NiklasEi/bevy_game_template) with a `#[mobile_entry_point]` attribute on `main`, which generates all the boilerplate `extern` functions for mobile. To run this on desktop, just do `cargo run` like normal! For mobile, use `cargo android run` and `cargo apple run` respectively (or use `cargo android open` and `cargo apple open` to open in Android Studio and Xcode respectively). - -Note that we've deliberately omitted the font used by the demo, since if the font loads successfully, it seems to trigger a text rendering crash in bevy. diff --git a/templates/apps/bevy-demo/src/lib.rs.hbs b/templates/apps/bevy-demo/src/lib.rs.hbs index 16aa0011..f0673abd 100644 --- a/templates/apps/bevy-demo/src/lib.rs.hbs +++ b/templates/apps/bevy-demo/src/lib.rs.hbs @@ -1,5 +1,4 @@ - -use bevy::window::WindowMode; +use bevy::window::{WindowMode, MonitorSelection}; use bevy::{color::palettes::css::PURPLE, prelude::*}; use winit::event_loop::EventLoop; @@ -33,7 +32,7 @@ pub fn main() { primary_window: Some(Window { name: Some("{{app.stylized-name}}".to_string()), resizable: false, - mode: WindowMode::BorderlessFullscreen, + mode: WindowMode::BorderlessFullscreen(MonitorSelection::Primary), ..default() }), ..default() @@ -68,11 +67,13 @@ fn setup_audio(mut commands: Commands, asset_server: Res) { fn setup_player(mut commands: Commands, asset_server: Res) { commands - .spawn(SpriteBundle { - texture: asset_server.load("textures/bevy.png"), - transform: Transform::from_translation(Vec3::new(0., 0., 1.)), - ..Default::default() - }) + .spawn(( + Sprite { + image: asset_server.load("textures/bevy.png"), + ..Default::default() + }, + Transform::from_translation(Vec3::new(0., 0., 1.)), + )) .insert(Player); } @@ -133,7 +134,7 @@ pub fn handle_touch( if let Some(touch_position) = touch_input.first_pressed_position() { let (camera, camera_transform) = camera.single(); - if let Some(touch_position) = camera.viewport_to_world_2d(camera_transform, touch_position) + if let Some(touch_position) = camera.viewport_to_world_2d(camera_transform, touch_position).ok() { let diff = touch_position - player.single().translation.xy(); if diff.length() > FOLLOW_EPSILON { @@ -162,8 +163,8 @@ fn move_player( } let speed = 150.; let movement = Vec3::new( - actions.player_movement.unwrap().x * speed * time.delta_seconds(), - actions.player_movement.unwrap().y * speed * time.delta_seconds(), + actions.player_movement.unwrap().x * speed * time.delta_secs(), + actions.player_movement.unwrap().y * speed * time.delta_secs(), 0., ); for mut player_transform in &mut player_query { @@ -179,7 +180,7 @@ fn move_player( Ok(_) => {} Err(_) => { commands.spawn((AudioBundle { - source: audio.clone(), + source: bevy::prelude::AudioPlayer(audio.clone()), settings: PlaybackSettings::DESPAWN, ..default() },)); diff --git a/templates/apps/bevy/src/lib.rs.hbs b/templates/apps/bevy/src/lib.rs.hbs index 2893363a..8d561190 100644 --- a/templates/apps/bevy/src/lib.rs.hbs +++ b/templates/apps/bevy/src/lib.rs.hbs @@ -1,4 +1,4 @@ -use bevy::window::WindowMode; +use bevy::window::{WindowMode, MonitorSelection}; use bevy::prelude::*; #[bevy_main] @@ -8,7 +8,7 @@ fn main() { primary_window: Some(Window { name: Some("{{app.stylized-name}}".to_string()), resizable: false, - mode: WindowMode::BorderlessFullscreen, + mode: WindowMode::BorderlessFullscreen(MonitorSelection::Primary), ..default() }), ..default() @@ -23,5 +23,5 @@ fn setup( ) { let texture_handle = asset_server.load("branding/icon.png"); commands.spawn(Camera2dBundle::default()); - commands.spawn(SpriteBundle {texture: texture_handle, ..Default::default()}); + commands.spawn(Sprite {image: texture_handle, ..Default::default()}); }