Spark AR脚本不会启动功能
我有一个Spark AR Instagram过滤器的脚本。我希望它成为一个...您是否过滤。 我的问题是,我无法通过在屏幕上敲击滤镜来启动过滤器。我认为它仅开始经历主要循环,但我不知道为什么它会停止。我是在使用旧的API还是功能?
这是我的代码:
// Spark AR APIs
const Time = require('Time');
const Patches = require('Patches');
const Instruction = require('Instruction');
const Materials = require('Materials');
const Textures = require('Textures')
// Objects
const display0 = Materials.getAll('display');
const pics = ['pic1', 'pic2', 'pic3'];
// Variables
let randInterval = null;
let status = 'ready';
// Setting Initial Instruction
Instruction.bind(true, 'tap_to_start');
// Main loop
Patches.outputs.getPulse('tap').then(value => value.subscribe(() => {
Instruction.bind(false, 'tap_to_start')
if (status === 'ready') {
start();
}
else if (status === 'running'){
return;
}
else if (status === 'finished'){
reset();
}
}));
// Functions
function start(){
status = 'running';
randInterval = Time.setInterval(function (){
randomImage();
}, 100);
beginCountDown();
};
function beginCountDown(){
Time.setTimeout(function(){
stop();
}, 3000);
};
function stop(){
Time.clearInterval(randInterval);
Instruction.bind(true, 'tap_to_reply')
status = "finished";
};
function reset(){
Instruction.bind(false, 'tap_to_reply')
Instruction.bind(true, 'tap_to_start')
display0.diffuse = Textures.get('SPARKLE');
status = 'ready';
};
// Logic Functions
function randomImage(){
let randomNumber = randomlyChoose(0, pics.length);
let pickedImage = pics[randomNumber]
display0.diffuse = Textures.get(pickedImage);
};
function randomlyChoose(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min)
};
I have a script for a Spark AR Instagram Filter. I want it to be an which... are you filter.
My Problem is, that i can't start the filter by tapping on the screen. I think it only starts going through th main loop, but I have no Idea on why it stops. Am I using old APIs or Functions?
Here is my code:
// Spark AR APIs
const Time = require('Time');
const Patches = require('Patches');
const Instruction = require('Instruction');
const Materials = require('Materials');
const Textures = require('Textures')
// Objects
const display0 = Materials.getAll('display');
const pics = ['pic1', 'pic2', 'pic3'];
// Variables
let randInterval = null;
let status = 'ready';
// Setting Initial Instruction
Instruction.bind(true, 'tap_to_start');
// Main loop
Patches.outputs.getPulse('tap').then(value => value.subscribe(() => {
Instruction.bind(false, 'tap_to_start')
if (status === 'ready') {
start();
}
else if (status === 'running'){
return;
}
else if (status === 'finished'){
reset();
}
}));
// Functions
function start(){
status = 'running';
randInterval = Time.setInterval(function (){
randomImage();
}, 100);
beginCountDown();
};
function beginCountDown(){
Time.setTimeout(function(){
stop();
}, 3000);
};
function stop(){
Time.clearInterval(randInterval);
Instruction.bind(true, 'tap_to_reply')
status = "finished";
};
function reset(){
Instruction.bind(false, 'tap_to_reply')
Instruction.bind(true, 'tap_to_start')
display0.diffuse = Textures.get('SPARKLE');
status = 'ready';
};
// Logic Functions
function randomImage(){
let randomNumber = randomlyChoose(0, pics.length);
let pickedImage = pics[randomNumber]
display0.diffuse = Textures.get(pickedImage);
};
function randomlyChoose(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min)
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论