text2d example: animate_scale no longer unnecessarily performs the same translation at each Update (#11936)
# Objective - The `transform.translation` of a `TextBundle` in this example is unnecessarily set to the same constant position over and over in each `Update`. Newbies might be confused as to why this translation is being performed over and over. ## Solution - perform the translation only once, when the `Text2dBundle` is instantiated
This commit is contained in:
parent
2ae50874d3
commit
24e8e67b91
@ -63,6 +63,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||||||
commands.spawn((
|
commands.spawn((
|
||||||
Text2dBundle {
|
Text2dBundle {
|
||||||
text: Text::from_section("scale", text_style).with_justify(text_justification),
|
text: Text::from_section("scale", text_style).with_justify(text_justification),
|
||||||
|
transform: Transform::from_translation(Vec3::new(400.0, 0.0, 0.0)),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
AnimateScale,
|
AnimateScale,
|
||||||
@ -187,8 +188,6 @@ fn animate_scale(
|
|||||||
// Consider changing font-size instead of scaling the transform. Scaling a Text2D will scale the
|
// Consider changing font-size instead of scaling the transform. Scaling a Text2D will scale the
|
||||||
// rendered quad, resulting in a pixellated look.
|
// rendered quad, resulting in a pixellated look.
|
||||||
for mut transform in &mut query {
|
for mut transform in &mut query {
|
||||||
transform.translation = Vec3::new(400.0, 0.0, 0.0);
|
|
||||||
|
|
||||||
let scale = (time.elapsed_seconds().sin() + 1.1) * 2.0;
|
let scale = (time.elapsed_seconds().sin() + 1.1) * 2.0;
|
||||||
transform.scale.x = scale;
|
transform.scale.x = scale;
|
||||||
transform.scale.y = scale;
|
transform.scale.y = scale;
|
||||||
|
Loading…
Reference in New Issue
Block a user