【问题标题】:Parsing scalar number to text in Spark AR在 Spark AR 中将标量数字解析为文本
【发布时间】:2021-07-10 05:32:39
【问题描述】:

我正在尝试将设备运动值链接到 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

Patch I used

My To and From script values

如果有人知道脚本为什么不起作用,请帮助我。

【问题讨论】:

    标签: javascript spark-ar-studio


    【解决方案1】:

    API 更改为基于 Promise。这意味着 Patches.getScalarValue() 会给你一个承诺。 这个脚本应该可以工作:

    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 的错误。

    【讨论】:

      猜你喜欢
      • 2018-03-20
      • 1970-01-01
      • 2017-07-21
      • 2018-10-12
      • 1970-01-01
      • 2012-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多