我正在尝试将设备运动值链接到 2D 文本元素,以便旋转 Y 值将在我的场景中显示为文本。
我一直在尝试实现 another thread 中描述的解决方案,没有运气。显然,自 2020 年 3 月发布 v85 以来,Spark AR 中的脚本工作方式发生了一些变化。
这是我在项目中使用的代码:
const Patches = require('Patches');
const numberFormat = 'Time: {0}';
const number = Patches.getScalarValue('number');
Patches.setStringValue('value', number.format(numberFormat));
This is what my script looks like in the editor
如果有人知道为什么脚本不起作用,请帮助我。
最佳答案
API 更改为基于 Promise。这意味着 Patches.getScalarValue() 会给你一个 Promise。 这个脚本应该可以工作:
const Patches = require('Patches');
// enable async/await
(async () => {
const numberFormat = 'Time: {0}';
const number = await Patches.getScalarValue('number');
Patches.setStringValue('value', number.format(numberFormat));
})()
此外,您也没有提供来自 SparkAR Studio 的错误。
关于javascript - 在 Spark AR 中将标量数字解析为文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68202392/