假设我创建了一个容器
let created = UiWidget::Container::<NoCustomUi, String, ()> {
transform: UiTransformData::default(),
background: None,
children: Vec::new(),
};我如何将它添加到世界中并取回它的实体?类似于:
let entity = world
.create_entity()
.with(container)
.build();但是它说“特征specs::world::comp::Component不是为amethyst_ui::prefab::UiWidget<amethyst_ui::prefab::NoCustomUi, std::string::String>实现的”。
我使用的是紫晶0.15版
发布于 2020-08-19 06:43:50
UiWidget实际上不能直接添加到Entity中,因为它是通过Prefab加载的
您必须创建UiTransform、UiText或amethyst::ui中少数几个实现Component的其他Struct之一,并将它们添加到Entity中
let ui_transform = UiTransform::new(
String::from("demo_text"), // id
Anchor::Middle, // anchor
Anchor::Middle, // pivot
0f32, // x
0f32, // y
0f32, // z
100f32, // width
30f32, // height
);
let ui_text = UiText::new(
font_handle, // font
String::from("Hello World"), // text
[1.0, 1.0, 1.0, 0.5], // color
25f32, // font_size
LineMode::Single, // line mode
Anchor::Middle, // alignment
);
world.create_entity()
.with(ui_transform)
.with(ui_text)
.build();你可以在User Interface section下的紫晶一书中找到更多关于如何做到这一点的信息。
https://stackoverflow.com/questions/62964870
复制相似问题