Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added level intro and player indicator
- Loading branch information
1 parent
54e3a74
commit 5d1b2be
Showing
8 changed files
with
303 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use crate::game_camera::PanOrbitCamera; | ||
use bevy::prelude::*; | ||
use bevy::render::camera::*; | ||
|
||
pub struct FollowTextPlugin; | ||
impl Plugin for FollowTextPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.add_system(update_text_position); | ||
} | ||
} | ||
|
||
#[derive(Component)] | ||
pub struct FollowText { | ||
pub following: Entity, | ||
} | ||
|
||
fn update_text_position( | ||
windows: Res<Windows>, | ||
mut text_query: Query<(&mut Style, &CalculatedSize, &FollowText)>, | ||
mesh_query: Query<&Transform>, | ||
camera_query: Query<(&Camera, &GlobalTransform), With<PanOrbitCamera>>, | ||
) { | ||
for (mut style, calculated, follow) in text_query.iter_mut() { | ||
if let Ok(mesh_position) = mesh_query.get(follow.following) { | ||
for (camera, camera_transform) in camera_query.iter() { | ||
match camera.world_to_screen(&windows, camera_transform, mesh_position.translation) | ||
{ | ||
Some(coords) => { | ||
style.position.left = Val::Px(coords.x - calculated.size.width / 2.0); | ||
style.position.bottom = | ||
Val::Px((coords.y * 1.4) - calculated.size.height / 2.0); | ||
} | ||
None => { | ||
// A hack to hide the text when the it's behind the camera | ||
style.position.bottom = Val::Px(-1000.0); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.