rust - 如何重用加载在紫水晶中的资产?
问题描述
我正在Amethyst中构建一个简单的按钮,现在我想重用font_handle
用于加载资产的按钮。这是我当前的代码:
pub fn create_button(world: &mut World) {
let font_handle = world.read_resource::<Loader>().load(
"fonts/Bangers-Regular.ttf",
TtfFormat,
(),
&world.read_resource(),
);
// ....
world
.create_entity()
// ....
.with(UiTransform::new(
String::from("simple_button"), // id
Anchor::Middle, // anchor
Anchor::Middle, // pivot
40.0,
-40.,
1.,
200.,
50.,
))
// button text
.with(UiText::new(
font_handle, // font
String::from("Simple Button"), // text
[1.0, 1.0, 1.0, 0.5], // color
25f32, // font_size
LineMode::Single, // line mode
Anchor::Middle, // alignment
))
.with(UiTransform::new(
String::from("simple_button_2"), // id
Anchor::Middle, // anchor
Anchor::Middle, // pivot
50.0,
-40.,
1.,
200.,
50.,
))
// button text
.with(UiText::new(
font_handle, // font
String::from("Simple Button 2"), // text
[1.0, 1.0, 1.0, 0.5], // color
25f32, // font_size
LineMode::Single, // line mode
Anchor::Middle, // alignment
))
.build();
我得到的错误非常明确,我的直觉说它与指针和克隆有关 - 就像我们对紫水晶中的大多数对象所做的那样。我试过了,但没有用。这是错误消息:
error[E0382]: use of moved value: `font_handle`
--> src/state.rs:188:13
|
135 | let font_handle = world.read_resource::<Loader>().load(
| ----------- move occurs because `font_handle` has type `amethyst::amethyst_assets::Handle<FontAsset>`, which does not implement the `Copy` trait
...
169 | font_handle, // font
| ----------- value moved here
...
188 | font_handle, // font
| ^^^^^^^^^^^ value used here after move
我能想到的另一种方法是制作自定义资产加载器 - 这是唯一的方法还是有更简单的方法来实现重用?
解决方案
推荐阅读
- cucumber - 如何为步骤定义和其他类文件共享相同的驱动程序
- docker - 如何将某些文件标记为 docker 是 Vscode?
- javascript - 尝试从 URL 检索网站图标
- selenium - 使用 chromedriver 2.41 和 2.42 与 chrome 69 查找元素并发送密钥无法正常工作
- eclipse - Eclipse Photon 在 Ubuntu 18.04 上重绘按键
- elasticsearch - ElasticSearch 布尔查询到 Solrj 查询
- css - CSS box-shadow vs 轮廓
- pepper - 为什么辣椒的平板电脑停止播放视频?
- c# - [MyMvcProject].Views.dll 的汇编版本
- javascript - 为什么没有将类添加到我的元素中?