#Move Text Around on screen
35 messages · Page 1 of 1 (latest)
And changing the style is also inconsistent as they're al Vals and you can't apply addition to Vals, only multiplication
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);
oh that works? I thought I tried that but I couldn't get it to work
hmm, that specifically doesn't fully work though. it gives this error
`else` clause of `let...else` does not diverge
expected type `!`
found enum `bevy::prelude::Val`
try adding a diverging expression, such as `return` or `panic!(..)`
...or use `match` instead of `let...else`
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);
}
Let else need to return or stop The function someway apparently
The problem probably is that you need to assign an value beforehand to the style, otherwise it'll be Auto
i mean I have it assigned on creation?
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
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
Have you assigned it to style.left explicit? IIRC, Val implement Copy, so maybe you are not changing The reference, but a copy
i tried this, didn't work either
That's odd, is there other system that maybe are changing The value?
Or maybe you can check in another system if the Style is in fact being changed
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
Sure, and is it being changed? Dunno if the parents style can affect in this matter
oh! something did move, but for some reason it seemed to only do so on like, the last moment of its existence
Is it being despawned?
yeah
Maybe the velocity isn't enough, try to apply something very large, like 100 or 200 and see if it goes away
already set it to 100 actually, that's when I saw the change but now I don't even see that anymore
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?
with this method I don't see any difference in the values or the visuals though
this is my entire function that does anything with the popups
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
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
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