首页 > 解决方案 > 如何在脚本中获取循环动画进度(Spark AR)

问题描述

我需要获取循环动画进度(和循环)信息(如果它在补丁编辑器中,它就是输出)。但我在文档中找不到这些信息。我怎样才能获得所需的信息?

标签: spark-ar-studio

解决方案


对于“循环”,您可以在 TimeDriver 上使用 onAfterIteration 事件: https ://sparkar.facebook.com/ar-studio/learn/documentation/reference/classes/animationmodule.timedriver

对于进度,遗憾的是 TimeDriver 上没有可用的进度,但您可以在动画信号上使用 multiTrigger 事件侦听器。根据您要实现的具体目标,有几种不同的方法: https ://sparkar.facebook.com/ar-studio/learn/documentation/reference/classes/reactivemodule.scalarsignal

例如:

//setup your animation
const Animation = require('Animation');
let driver = Animation.timeDriver({durationMilliseconds:1000, loopCount:Infinity});
let sampler = Animation.samplers.linear(0,1);
let animation = Animation.animate(driver, sampler);

//add listener for "looped" to the driver
driver.onAfterIteration().subscribe(function(e){
  //do stuff on here...

});

//add listener for progress to the animation signal
//this will trigger when the animation signal goes above .5
animation.multiTrigger(.5).subscribe(function(e){
  //do stuff here...

})

推荐阅读