Hello people!
I'm trying to make a game that's played on a backgammon board, and I'm running into some difficulties on how to best draw the board to the screen and make it responsive and fit within the ui.
The UI is a flex column.
fn setup_ui(...) {
// Spawn board first
spawn_board(&mut commands, &mut meshes, &mut materials);
// Then spawn UI
commands
.spawn((
Node {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
flex_direction: FlexDirection::Column,
justify_content: JustifyContent::Stretch,
..default()
},
PickingBehavior::IGNORE,
))
.with_children(|parent| {
//top horizontal fill
parent.spawn(...)
// center horizontal fill - board container
parent.spawn((
Node {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
flex_direction: FlexDirection::Column,
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
},
PickingBehavior::IGNORE,
));
// bottom horizontal fill
parent.spawn(...);
}
The board is a 2d mesh
pub fn spawn_board(...) {
commands
.spawn((
Mesh2d(meshes.add(Rectangle::from_size(BOARD_SIZE))),
Transform::default(),
MeshMaterial2d(materials.add(BOARD_COLOR)),
))
.with_children(|parent| {
spawn_board_triangles(parent, meshes, &triangle_materials);
});
}
But this isn't responsive and, the UI covers the board if we resize the window. I tried to parent the UI to the board, but then it showed "behind".
Could anyone point me in the right direction?