【发布时间】:2022-12-30 11:52:32
【问题描述】:
我已经有一个在浏览器中运行的 bevy 应用程序。
我想做的是在 js/ts 方面有一些功能,可以在 bevy 世界中创建或销毁实体,这可能吗?我已经尝试let app=App::new();,然后绑定一个函数来运行应用程序app.run();,并绑定一个函数来覆盖资源app.insert_resource(...);。但是当我在运行应用程序后调用函数来覆盖资源时,它会显示错误消息:递归使用检测到的对象,这将导致锈蚀中的不安全别名。
感谢@kmdreko 的建议,我尝试使用 Arc 更新 resrouce,但在此之前似乎还有另一个问题,问题是在我初始化 bevy 应用程序之后,其余代码将永远无法访问,这是我的代码:
<script type="module">
import init, {BevyApp} from '../pkg/wasm_bevy_demo.js';
init().then(() => {
// new() function create and run a bevy app, and return a Arc<Mutex> in BevyApp{}
const bevyCode = BevyApp.new();
// this log info never show in the console
console.log("reach after run bevy app");
bevyCode.update_scroll_rate(10, 10);
})
</script>
【问题讨论】:
-
只是一个猜测,但您可能会尝试修改现有资源,而不是使用
insert_resource覆盖它。不过,您可能必须使用共享可变性(Arc<Mutex>或Rc<RefCell>)。
标签: rust wasm-bindgen bevy