Scripting 通过脚本在Spark AR中动态生成值

Scripting 通过脚本在Spark AR中动态生成值,scripting,instagram,reactive,spark-ar-studio,Scripting,Instagram,Reactive,Spark Ar Studio,从这个问题开始,我现在尝试使开始和结束颜色动态地有界。我可能还没有完全接受反应式编程的概念,但我尝试创建一个工厂,使其值成为一个函数。。。但它不起作用,或者只对初始值起作用。使用设置功能并重新启动动画不会改变任何事情。我错过了什么?谢谢你,并致以最良好的问候 const pink = [.99, .682, .721, 1]; const blue = [.0094, .0092, .501, 1]; const yellow = [0.9372, .7725, 0, 1]; function

从这个问题开始,我现在尝试使开始和结束颜色动态地有界。我可能还没有完全接受反应式编程的概念,但我尝试创建一个工厂,使其值成为一个函数。。。但它不起作用,或者只对初始值起作用。使用设置功能并重新启动动画不会改变任何事情。我错过了什么?谢谢你,并致以最良好的问候

const pink = [.99, .682, .721, 1];
const blue = [.0094, .0092, .501, 1];
const yellow = [0.9372, .7725, 0, 1];

function ColorFactory() {
    this.sourceCol = pink;
    this.targetCol = blue;

    this.set = function (_col1, _col2) {
        this.sourceCol = _col1;
        this.targetCol = _col2;
    }

    this.get = function (id) {
        switch (id) {
            case 'source': return this.sourceCol;
            default: return this.targetCol;
        }
    }
}


var colfac = new ColorFactory();

const timeDriver = Animation.timeDriver(timeDriverParameters);
const rotSampler = Animation.samplers.easeInQuad(0, 35);
const alphaSampler = Animation.samplers.linear(1, 0);
const colSampler = Animation.samplers.linear(colfac.get('source'), colfac.get('target'));
const colorAnimation = Animation.animate(timeDriver, colSampler);

timedriver.start();

//doesnt make change anything, same colors as before:
colfac.set(blue, yellow);
timedriver.reset();
timedriver.start();
那么,我怎样才能使这套颜色具有动态性呢?有人吗?

对你来说,唯一的“好”选择就是这样做:

const colors=[];
const driver=A.timeDriver({duration毫秒:1000});
//在NativeUI上监视选定的索引事件
ui.selectedIndex.monitor.subscribe(
(val)=>{
const sampler=A.samplers.linear(颜色[val.oldValue,颜色[val.newValue]);
const colorAnimation=A.animate(驱动程序、采样器);
//在此处绑定到着色器
})

当您创建一个sampler实例时,您不能更改它,但可以创建一个新实例。当然,您需要再次绑定动画。这将适用于离散的颜色更改,但不适用于平滑的更改。那么您希望实现什么样的效果?您能澄清吗?嗨,是的,我意识到我必须创建一个新的sampler,但它可以我想知道…有一个过渡补丁,它完全符合我的需要,用动态源和目标值为v3制作动画。由于所有补丁都必须在脚本中有一个等效的,我想知道这可能是什么,以澄清:我有一个不同颜色的产品。我希望用户单击nativeui按钮,让选定的颜色消失由于用户可以按任何顺序点击,我必须有可能动态设置源和目标值。通过在每次点击时创建新的采样器和动画,我已经实现了我的目标,但我觉得我不是很优雅…好的,你想要从一种颜色过渡到另一种颜色,对吗?顺便说一下,补丁和我们使用的“脚本”具有不同的访问级别。我们处于孤立的气泡中,在这里不能做很多事情,一切都是被禁止的(在补丁中,我猜您将使用计数器在颜色之间切换。我已经在脚本中实现了我的版本,但它看起来有点奇怪,并且基于时间驱动程序。主要功能是在“vanila js”和“reactive js”之间架起一座桥梁。