Things are rendering ok

This commit is contained in:
Daniel Flanagan 2024-07-31 16:39:53 -05:00
parent d24bf8defc
commit d05fc09e8a
4 changed files with 50 additions and 42 deletions

View file

@ -1,17 +1,20 @@
use bevy::prelude::*; use crate::prelude::*;
use bevy::render::camera::Camera; use bevy::render::camera::{Camera, ScalingMode};
pub fn startup(mut commands: Commands) { // #[derive(Component)]
let mut bundle = (Camera2dBundle::default(), IsDefaultUiCamera); // struct GameCamera;
bundle.0.projection = OrthographicProjection {
pub fn startup(mut commands: Commands, mut ui_scale: ResMut<UiScale>) {
let mut bundle = Camera2dBundle::default();
bundle.projection = OrthographicProjection {
near: f32::MIN, near: f32::MIN,
far: f32::MAX, far: f32::MAX,
scale: 1., scaling_mode: ScalingMode::FixedVertical(360.0 / 1.),
..default() ..default()
}; };
// bundle.0.transform.translation.z = f32::MAX; commands.spawn((bundle, IsDefaultUiCamera));
bundle.0.projection.scale = 1.;
commands.spawn(bundle); ui_scale.0 = 1.;
} }
#[derive(Component, Debug)] #[derive(Component, Debug)]

View file

@ -127,19 +127,20 @@ fn finish_setup(mut app_state: ResMut<NextState<View>>) {
app_state.set(View::MainMenu); app_state.set(View::MainMenu);
} }
fn startup(mut commands: Commands, mut ui_scale: ResMut<UiScale>) { fn startup(mut commands: Commands) {
let font_size = 48.;
commands.spawn(( commands.spawn((
FpsText, FpsText,
TextBundle::from_sections([ TextBundle::from_sections([
TextSection::new( TextSection::new(
"FPS: ", "FPS: ",
TextStyle { TextStyle {
font_size: 60., font_size,
..default() ..default()
}, },
), ),
TextSection::from_style(TextStyle { TextSection::from_style(TextStyle {
font_size: 60., font_size,
color: Color::hsla(0.5, 0.5, 0.5, 0.5), color: Color::hsla(0.5, 0.5, 0.5, 0.5),
..default() ..default()
}), }),
@ -151,8 +152,6 @@ fn startup(mut commands: Commands, mut ui_scale: ResMut<UiScale>) {
..default() ..default()
}), }),
)); ));
ui_scale.0 = 1.;
} }
fn update( fn update(

View file

@ -23,7 +23,7 @@ pub fn startup(mut commands: Commands) {
TextBundle::from_section( TextBundle::from_section(
"Text Example\nPress ENTER to play", "Text Example\nPress ENTER to play",
TextStyle { TextStyle {
font_size: 100.0, font_size: 64.0,
..default() ..default()
}, },
) )

View file

@ -3,7 +3,7 @@ use crate::movement::{Heading, Mover, Speed, Velocity, YSortable};
use crate::prelude::*; use crate::prelude::*;
use bevy::sprite::MaterialMesh2dBundle; use bevy::sprite::MaterialMesh2dBundle;
const PLAYER_SPEED: f32 = 1000.; const PLAYER_SPEED: f32 = 200.;
// #[derive(Resource, Default)] // #[derive(Resource, Default)]
// pub struct Layout(Handle<TextureAtlasLayout>); // pub struct Layout(Handle<TextureAtlasLayout>);
@ -26,6 +26,9 @@ pub fn startup(
mut meshes: ResMut<Assets<Mesh>>, mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>, mut materials: ResMut<Assets<ColorMaterial>>,
) { ) {
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( let layout = assets.add(TextureAtlasLayout::from_grid(
UVec2::new(32, 64), UVec2::new(32, 64),
3, 3,
@ -38,14 +41,8 @@ pub fn startup(
Player, Player,
YSortable, YSortable,
Watched, Watched,
SpriteBundle { Transform::default(),
texture: assets.load("img/Player.png"), GlobalTransform::default(),
..default()
},
TextureAtlas {
layout,
..default()
},
Mover { Mover {
velocity: Velocity(Vec2::ZERO), velocity: Velocity(Vec2::ZERO),
heading: Heading(Vec2::ZERO), heading: Heading(Vec2::ZERO),
@ -53,13 +50,35 @@ pub fn startup(
}, },
)) ))
.with_children(|player| { .with_children(|player| {
let mesh = meshes.add(Capsule2d::new(3.0, 25.0)); player.spawn((
let material = materials.add(Color::hsl(360. * 1 as f32 / 3 as f32, 0.95, 0.7)); SpriteBundle {
let transform = Transform::from_xyz(0.0, 0.0, 500.); 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(( player.spawn((
Crosshair, Crosshair,
// TODO: crosshair transform?
MaterialMesh2dBundle { MaterialMesh2dBundle {
mesh: mesh.into(), mesh: mesh.into(),
transform, transform,
@ -67,19 +86,6 @@ pub fn startup(
..default() ..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()
},));
}); });
} }