#Change text size after spawning the text
44 messages · Page 1 of 1 (latest)
Have a system access the TextStyle component of your text and there is a font_size property on the text style that may be changed
I know that but I can't figure out the syntax
For example, I changed the position of the text by doing this:
fn exit_death_screen(
mut score_style_query: Query<&mut Style, With<ScoreText>>
) {
for mut score in score_style_query.iter_mut() {
score.position.top.try_add_assign(Val::Px(300.0)).ok();
score.position.left.try_add_assign(Val::Px(250.0)).ok();
}
}
I can't figure out the syntax for the text size though.
could you try score.font_size += 300.0
i think you may be looking at the wrong variables on style
also it is TextStyle not Style
Thats weird cuz Style works just fine
I am gonna try your suggestion in a few minutes
score.font_size += 300 doesn't work
Also TextStyle doesn't work
it should be Style
Style is for the ui Node that contains the Text and TextStyle is for the actual text itself
Also, TextStyle is not a component
it's in a Text section
so you'd need to query for Text and then do something like text.sections[0].font_size
or something close to that
I understand.
So it should be something like this:
fn exit_death_screen(
mut commands: Commands,
mut score_style_query: Query<&mut Style, With<ScoreText>>,
mut score_text_query: Query<&mut Text, With<ScoreText>>
) {
for mut score_style in score_style_query.iter_mut() {
score_style.position.top.try_add_assign(Val::Px(500.0)).ok();
score_style.position.left.try_add_assign(Val::Px(550.0)).ok();
}
for mut score_text in score_text_query.iter_mut() {
score_text.sections[0].font_size
}
}
I can't figure out the syntax though
it says ''no field font_size"
should be sections[0].style.font_size I think
that could work but then how do I set the font size
score_text.sections[0].style.font_size(Val::Px(500));
could this work
also, you could do it in one query
fn exit_death_screen(
mut commands: Commands,
mut score_style_query: Query<(&mut Style, &mut Text), With<ScoreText>>,
) {
for (mut score_style, mut text) in score_style_query.iter_mut() {
score_style.position.top.try_add_assign(Val::Px(500.0)).ok();
score_style.position.left.try_add_assign(Val::Px(550.0)).ok();
text.sections[0].style.font_size = 16.0;
}
}
font_size is just an f32
I see
are you using rust-analyzer? It should help you show this information
I am it just takes a while to load
right, yeah, it can be pretty slow sometimes
Sometimes I just reload the vscode window and it seems to help
I kinda just wait for it
I think it should work now though
I'm waiting for the game to run but the analyzer says its fine
I didn't get an error but it didn't work
the text stayed the same size
nvm my bad
I think it should work
I had accidentally placed it in the wrong system
I have 2 systems which are almost identical and I had placed it in the one that wasn't running
It should work now, I'm waiting for the game to run
Yeah, it works. Thank you for the help!