#Move Text Around on screen

35 messages · Page 1 of 1 (latest)

scarlet furnace
#

Is there any way to move text around on screen consistently? Idk if I'm just being dumb but I can't see a way to move text after it's in the world, only the change the style which seems to not do anything when I've tried it

#

And changing the style is also inconsistent as they're al Vals and you can't apply addition to Vals, only multiplication

torn quiver
#

You can assign to &mut Style. So you'd

let Val::Px(left) = style.left else { Val::Px(0) };
style.left = Val::Px(left + 10.0); 
scarlet furnace
#

oh that works? I thought I tried that but I couldn't get it to work

scarlet furnace
#

and i'm not sure what to do with that, as in how to write that

#

changed it to this and the value goes up but it doesn't actually move

 if let Val::Px(bottom) = s.bottom{
            s.bottom = Val::Px(bottom + 10.0); 
        }
tender sand
tender sand
scarlet furnace
#

i mean I have it assigned on creation?

tender sand
#

You can something like:

let style_bind = if let Val::Px(x) = style.left {
 Val::Px(x + 10.)
} else {
 Val::Px(0)
}

style.left = style_bind
scarlet furnace
#

and if I put a println in the if statement and print out the s.bottom, i can clearly see its going up, just not visually

tender sand
scarlet furnace
#

no i've assigned it like within the Style component

#

like this

scarlet furnace
tender sand
#

Or maybe you can check in another system if the Style is in fact being changed

scarlet furnace
#

nope, there's only one that's touching it

#

i have nothing else interacting with a style, i checked ;P

#

this is the only query that even contains style

tender sand
#

Sure, and is it being changed? Dunno if the parents style can affect in this matter

scarlet furnace
#

oh! something did move, but for some reason it seemed to only do so on like, the last moment of its existence

scarlet furnace
#

yeah

tender sand
#

Maybe the velocity isn't enough, try to apply something very large, like 100 or 200 and see if it goes away

scarlet furnace
#

already set it to 100 actually, that's when I saw the change but now I don't even see that anymore

tender sand
#

Probably worth an look at that despawning system or the system that You are using to apply the velocity, do you set the entity to despawn with some component, and then try to move it?

scarlet furnace
#

with this method I don't see any difference in the values or the visuals though

scarlet furnace
tender sand
#

My only guess is that th3 entity is being despawned before it can do something with the style. A test that you can do is add more time just for test (something like, 10 seconds just to be sure) and see if it can apply the movement

scarlet furnace
#

so, when I use this statement, I can print the value of bottom. I can see that in this instance it goes up. I can even put a printline outside and print s.bottom, and it's going up. It even goes up to like 6000 before it disappears. Clearly it should have gone up ages ago, but it's very clearly not moved at all. It's like it's just not updating visually

tender sand
#

Made some search here and there, trying the same thing, and for me at least is working
Here is an example of what I did

#
fn delay_visibility(
    mut local: Local<bool>,
    mut window: Query<&mut Window>,
    mut options: ResMut<UiDebugOptions>,
    mut query: Query<&mut Style, With<Marker>>,
    frames: Res<FrameCount>,
) {
    if frames.0 == 3 {
        window.single_mut().visible = true;
        options.toggle();
    }
    for mut s in query.iter_mut() {
        if let Val::Px(x) = s.bottom {
            let mut vel;
            if *local {
                vel = 10.;
                if x > 1000. {
                    *local = false;
                    vel = -10.
                }
            } else {
                vel = -10.;
                if x < 0. {
                    *local = true;
                    vel = 10.
                }
            }
            s.bottom = Val::Px(x + vel);
        }
    }
}
#[derive(Component)]
struct Marker;
pub fn setup_camera(mut commands: Commands, asset: Res<AssetServer>) {
    commands.spawn(Camera2dBundle::default());
    commands.spawn(NodeBundle {
        style: Style {
            min_width: Val::Px(50.),
            min_height: Val::Px(40.),
            position_type: PositionType::Absolute,
            bottom: Val::Px(100.),
            ..Default::default()
        },
        background_color: BackgroundColor(Color::rgb(1., 1., 1.)),
        ..Default::default()
    }).with_children(|parent| {
        parent.spawn(TextBundle::from_sections([
            TextSection {
                style: TextStyle { font: asset.load("font.ttf"), ..Default::default() },
                value: "Texto".to_string()
            },
            TextSection {
                style: TextStyle { font: asset.load("font.ttf"), color: Color::rgb(1., 0., 0.),..Default::default() },
                value: "Texto 2".to_string()
            },
        ]).with_style(Style { position_type: PositionType::Absolute, bottom: Val::Px(100.), ..Default::default() })).insert(Marker);
    })
    ;
}

#

very silly, just moving the text here and there