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 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<UiScale>) {
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)]

View file

@ -127,19 +127,20 @@ fn finish_setup(mut app_state: ResMut<NextState<View>>) {
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((
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<UiScale>) {
..default()
}),
));
ui_scale.0 = 1.;
}
fn update(

View file

@ -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()
},
)

View file

@ -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<TextureAtlasLayout>);
@ -26,6 +26,9 @@ pub fn startup(
mut meshes: ResMut<Assets<Mesh>>,
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(
UVec2::new(32, 64),
3,
@ -38,6 +41,16 @@ pub fn startup(
Player,
YSortable,
Watched,
Transform::default(),
GlobalTransform::default(),
Mover {
velocity: Velocity(Vec2::ZERO),
heading: Heading(Vec2::ZERO),
speed: Speed(PLAYER_SPEED),
},
))
.with_children(|player| {
player.spawn((
SpriteBundle {
texture: assets.load("img/Player.png"),
..default()
@ -46,20 +59,26 @@ pub fn startup(
layout,
..default()
},
Mover {
velocity: Velocity(Vec2::ZERO),
heading: Heading(Vec2::ZERO),
speed: Speed(PLAYER_SPEED),
));
let mut text = Text2dBundle {
text: Text::from_section(
"You",
TextStyle {
font_size: 16. * 4.,
color: Color::WHITE,
..default()
},
))
.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.);
),
..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()
},));
});
}