Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bevy templates upgrade to bevy 0.15 #428

Merged
merged 3 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion templates/apps/bevy-demo/Cargo.toml.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
4 changes: 1 addition & 3 deletions templates/apps/bevy-demo/README.md
Original file line number Diff line number Diff line change
@@ -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.
25 changes: 13 additions & 12 deletions templates/apps/bevy-demo/src/lib.rs.hbs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -68,11 +67,13 @@ fn setup_audio(mut commands: Commands, asset_server: Res<AssetServer>) {

fn setup_player(mut commands: Commands, asset_server: Res<AssetServer>) {
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);
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
},));
Expand Down
6 changes: 3 additions & 3 deletions templates/apps/bevy/src/lib.rs.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::window::WindowMode;
use bevy::window::{WindowMode, MonitorSelection};
use bevy::prelude::*;

#[bevy_main]
Expand All @@ -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()
Expand All @@ -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()});
}
Loading