Spark AR脚本不会启动功能

发布于 2025-02-03 05:39:11 字数 1770 浏览 5 评论 0原文

我有一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文