how to show text

main
Jordan Orelli 2 years ago
parent edb12e4dc5
commit 7adf3a01d0

Binary file not shown.

@ -0,0 +1,61 @@
use bevy::prelude::*;
const DEBUG_PINK: Color = Color::rgb(0.8, 0.2, 0.2);
#[derive(Component)]
struct DebugView;
pub struct DebugViewPlugin;
impl Plugin for DebugViewPlugin {
fn build(&self, app: &mut App) {
info!("setting up the DebugView plugin");
app
.add_startup_system(init_view)
.add_system(debug_input);
}
}
fn init_view(mut commands: Commands, asset_server: Res<AssetServer>) {
let mut root = commands.spawn();
root.insert(DebugView);
root.insert_bundle(NodeBundle{
visibility: Visibility{is_visible: false},
style: Style{
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),
..default()
},
color: Color::NONE.into(),
..default()
});
root.with_children(|parent| {
let textStyle = TextStyle{
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font_size: 20.0,
color: DEBUG_PINK,
};
let textBundle = TextBundle::from_section("fart", textStyle)
.with_text_alignment(TextAlignment::TOP_RIGHT)
.with_style(Style{
align_self: AlignSelf::FlexEnd,
position_type: PositionType::Absolute,
position: UiRect {
top: Val::Px(5.0),
right: Val::Px(5.0),
..default()
},
..default()
});
parent.spawn_bundle(textBundle);
});
}
fn debug_input(now: Res<Input<KeyCode>>, mut query: Query<&mut Visibility, With<DebugView>>) {
let mut visibility = query.single_mut();
if now.just_pressed(KeyCode::F10) {
visibility.is_visible = !visibility.is_visible;
}
}

@ -1,11 +1,13 @@
mod input;
mod debug_view;
use bevy::{
input::{keyboard::KeyCode, Input},
prelude::*,
};
use input::{PlayerInput, ButtonState};
use input::PlayerInput;
use debug_view::DebugViewPlugin;
#[derive(Component)]
struct Player;
@ -60,9 +62,6 @@ fn player_keyboard_input(now: Res<Input<KeyCode>>, mut input_state: ResMut<Playe
input_state.update(&now);
}
fn debug_input(now: Res<Input<KeyCode>>, mut debug_state: ResMut<DebugView>) {
}
fn player_movement(
mut query: Query<&mut Transform, With<Player>>,
input_state: Res<PlayerInput>,
@ -75,17 +74,18 @@ fn player_movement(
if input_state.right.pressed { player_t.translation.x += tile.width as f32; }
}
#[derive(Default, Debug)]
struct DebugView {
enabled: bool,
}
fn main() {
App::new()
.insert_resource(bevy::log::LogSettings{
// set to TRACE|DEBUG|INFO|WARN|ERROR to change log verbosity.
// INFO is the default level.
level: bevy::log::Level::INFO,
..default()
})
.add_plugins(DefaultPlugins)
.add_plugin(DebugViewPlugin)
.insert_resource(ClearColor(BACKGROUND_COLOR))
.insert_resource(PlayerInput::default())
.insert_resource(DebugView::default())
.insert_resource(TileSize{width: TILE_WIDTH, height: TILE_HEIGHT})
.add_startup_system(setup)
.add_system(player_keyboard_input)

Loading…
Cancel
Save