From d05fc09e8a443529f9becbf02e00303b7c9a15aa Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Wed, 31 Jul 2024 16:39:53 -0500 Subject: [PATCH] Things are rendering ok --- src/camera.rs | 21 +++++++++-------- src/main.rs | 9 ++++---- src/main_menu.rs | 2 +- src/player.rs | 60 ++++++++++++++++++++++++++---------------------- 4 files changed, 50 insertions(+), 42 deletions(-) diff --git a/src/camera.rs b/src/camera.rs index 37dc8f6..d828165 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -1,17 +1,20 @@ -use bevy::prelude::*; -use bevy::render::camera::Camera; +use crate::prelude::*; +use bevy::render::camera::{Camera, ScalingMode}; -pub fn startup(mut commands: Commands) { - let mut bundle = (Camera2dBundle::default(), IsDefaultUiCamera); - bundle.0.projection = OrthographicProjection { +// #[derive(Component)] +// struct GameCamera; + +pub fn startup(mut commands: Commands, mut ui_scale: ResMut) { + let mut bundle = Camera2dBundle::default(); + bundle.projection = OrthographicProjection { near: f32::MIN, far: f32::MAX, - scale: 1., + scaling_mode: ScalingMode::FixedVertical(360.0 / 1.), ..default() }; - // bundle.0.transform.translation.z = f32::MAX; - bundle.0.projection.scale = 1.; - commands.spawn(bundle); + commands.spawn((bundle, IsDefaultUiCamera)); + + ui_scale.0 = 1.; } #[derive(Component, Debug)] diff --git a/src/main.rs b/src/main.rs index e88b52d..8283aec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -127,19 +127,20 @@ fn finish_setup(mut app_state: ResMut>) { app_state.set(View::MainMenu); } -fn startup(mut commands: Commands, mut ui_scale: ResMut) { +fn startup(mut commands: Commands) { + let font_size = 48.; commands.spawn(( FpsText, TextBundle::from_sections([ TextSection::new( "FPS: ", TextStyle { - font_size: 60., + font_size, ..default() }, ), TextSection::from_style(TextStyle { - font_size: 60., + font_size, color: Color::hsla(0.5, 0.5, 0.5, 0.5), ..default() }), @@ -151,8 +152,6 @@ fn startup(mut commands: Commands, mut ui_scale: ResMut) { ..default() }), )); - - ui_scale.0 = 1.; } fn update( diff --git a/src/main_menu.rs b/src/main_menu.rs index 4ae5048..c2730c0 100644 --- a/src/main_menu.rs +++ b/src/main_menu.rs @@ -23,7 +23,7 @@ pub fn startup(mut commands: Commands) { TextBundle::from_section( "Text Example\nPress ENTER to play", TextStyle { - font_size: 100.0, + font_size: 64.0, ..default() }, ) diff --git a/src/player.rs b/src/player.rs index 4a88cc8..af7ac6c 100644 --- a/src/player.rs +++ b/src/player.rs @@ -3,7 +3,7 @@ use crate::movement::{Heading, Mover, Speed, Velocity, YSortable}; use crate::prelude::*; use bevy::sprite::MaterialMesh2dBundle; -const PLAYER_SPEED: f32 = 1000.; +const PLAYER_SPEED: f32 = 200.; // #[derive(Resource, Default)] // pub struct Layout(Handle); @@ -26,6 +26,9 @@ pub fn startup( mut meshes: ResMut>, mut materials: ResMut>, ) { + let mesh = meshes.add(Capsule2d::new(3.0, 25.0)); + let material = materials.add(Color::hsl(360. * 1 as f32 / 3 as f32, 0.95, 0.7)); + let transform = Transform::from_xyz(0.0, 0.0, 500.); let layout = assets.add(TextureAtlasLayout::from_grid( UVec2::new(32, 64), 3, @@ -38,14 +41,8 @@ pub fn startup( Player, YSortable, Watched, - SpriteBundle { - texture: assets.load("img/Player.png"), - ..default() - }, - TextureAtlas { - layout, - ..default() - }, + Transform::default(), + GlobalTransform::default(), Mover { velocity: Velocity(Vec2::ZERO), heading: Heading(Vec2::ZERO), @@ -53,13 +50,35 @@ pub fn startup( }, )) .with_children(|player| { - let mesh = meshes.add(Capsule2d::new(3.0, 25.0)); - let material = materials.add(Color::hsl(360. * 1 as f32 / 3 as f32, 0.95, 0.7)); - let transform = Transform::from_xyz(0.0, 0.0, 500.); - + player.spawn(( + SpriteBundle { + texture: assets.load("img/Player.png"), + ..default() + }, + TextureAtlas { + layout, + ..default() + }, + )); + let mut text = Text2dBundle { + text: Text::from_section( + "You", + TextStyle { + font_size: 16. * 4., + color: Color::WHITE, + ..default() + }, + ), + ..default() + }; + text.transform.scale.x = 0.25; + text.transform.scale.y = 0.25; + text.transform.translation.z = 500.0; + text.transform.translation.y = 24.; + player.spawn(text); + player.spawn((SpatialBundle::default(), SpatialListener::new(1.))); player.spawn(( Crosshair, - // TODO: crosshair transform? MaterialMesh2dBundle { mesh: mesh.into(), transform, @@ -67,19 +86,6 @@ pub fn startup( ..default() }, )); - player.spawn((SpatialBundle::default(), SpatialListener::new(1.))); - player.spawn((Text2dBundle { - text: Text::from_section( - "You", - TextStyle { - font_size: 18., - color: Color::WHITE, - ..default() - }, - ), - transform: Transform::from_translation(Vec3::new(30.0, -30.0, 0.)), - ..default() - },)); }); }