The forum on this site is closed for new comments and posts. Continue the conversation in our Snap AR Discord server.

Enable the tap command only after a certain event

  • // -----JS CODE-----

    // @input Component.SpriteVisual billboardSprite

    // @input Asset.AudioTrackAsset audioTrack

    // @input float showTime = 4.0

     

    var audioComponent = null;

     

     

    function onMouthOpened( eventData )

    {

    script.billboardSprite.getMaterial(0).getPass(0).baseColor = new vec4(1, 1, 1, 0.5);

     

    audioSetup();

     

    if( script.billboardSprite )

    {

    script.billboardSprite.enabled = false;

    }

    // Show billboard

    if( script.billboardSprite )

    {

    script.billboardSprite.enabled = true;

     

    // Start the delay

    delayedEvent.reset(script.showTime);

     

    // Play animation

    var control = script.billboardSprite.getMaterial(0).getPass(0).baseTex.control;

    if( control && control.play )

    {

    control.play(1, 0.0);

    }

    }

     

    // Play sound

    if( audioComponent )

    {

    audioComponent.play( 1 );

    }

    }

    var event = script.createEvent("MouthOpenedEvent");

    event.faceindex = 0;

    event.bind(onMouthOpened);

     

     

     

    function onDelay( eventData )

    {

    script.billboardSprite.enabled = false;

    }

     

    var delayedEvent = script.createEvent("DelayedCallbackEvent");

    delayedEvent.bind( onDelay );

     

    function audioSetup()

    {

    if( script.audioTrack && !audioComponent )

    {

    audioComponent = script.getSceneObject().createComponent("Component.AudioComponent");

    audioComponent.audioTrack = script.audioTrack;

    }

    }

    Comment actions Permalink
  • Hey Cristian, just to clarify to make sure I'm understanding what you're looking for:

    • You have something that happens on tap (for example, playing a sound and showing an image)
    • You want to disable the tap for a period of time while whatever happens finishes, then reenable the tap so that the user can tap again

    Is this correct?

    Comment actions Permalink
  • Hi Travis, thank you for your time.
    I have an event that activates when I open my mouth (a sound activates, lasts 4 seconds and a screen appears on the screen) and another one whose touching one side of the screen changes the object I see represented. When I open my mouth and then start the sound and the text I would like to block the ability to tap the screen and re-enable it when the event of sound and image end. Another thing, but I think that solving this also solves the other problem, when the last object appears on the screen, in addition to having sound and text activated when I open my mouth, also start a small animation, I would also block the tap until the audio is not finished, I hope I managed to explain

    Comment actions Permalink
  • Another thing, I also attach the code for the tap

     

    Comment actions Permalink
  • // -----JS CODE-----

    //@input SceneObject[] items

    // @input float showTime = 4.0

     

    //Array are indexd from 0.

    //Disable everythinh but the first (0th) item

     

     

     

    for (var i = 1; i < script.items.lenght; i++)

    {

     

    script.items[1].enable = false;

    }

     

     

    //Activate the next item on TouchStartEvent.

     

     

     

    // We remember what item is currently visible.

    // When we start it’s the 0th item.

    var currentItemIndex = 0;

     

    // Define what happens when you tap.

    function activateNextItem () {

     

    // Disable the current item.

    script.items[currentItemIndex].enabled = false;

     

    // Increment the current item index

    currentItemIndex += 1;

     

    // We need the current item index to wrap around

    // once it's higher than the number of items we have.

    currentItemIndex = currentItemIndex % script.items.length;

     

    // Enable the new item.

    script.items[currentItemIndex].enabled = true;

     

    }

     

    //Bind the function to the touch event.

    var touchEvent = script.createEvent("TapEvent");

    touchEvent.bind(activateNextItem)

     

     

    Comment actions Permalink
  • Hi Christian, this script I created should help steer you in the right direction. 

    It binds three events - open mouth, tap and a delayed event. When open mouth happens, there's a bool that disables the inside of the tap event. Then, it starts a delayed event with a configurable amount of time (make sure you tune in the inspector). When the delay event gets called, it re-enables the tap until the next open mouth. 

    https://pastebin.com/D1HMBr1h

    Comment actions Permalink
  • Hi Travis, you're a god!
    Thank you thank you!!!!

     

    Comment actions Permalink
  • Hi,

    can you help me with my Randomizer Script? 

    I have a lens with randomizer music (image_randomizer template) with TAP! event, for now if the user TAP the randomizer start but if TAP again the randomizer start again and I got double sound running at the same time,

    I would like to do: The user can`t  TAP again until the music stops

     

    Script:

     

    //@input Asset.Texture[] image {"label": "Images"}

    //@input Asset.Texture defaultTex {"label": "Defaul Texture"}

     

    //@input Component.Image bubble

     

    //@input bool advanced = false

     

    //@ui {"widget":"group_start", "label":"Advanced", "showIf": "advanced"}

    //@input float delayBetweenImages = 0.1 {"widget":"slider", "min":0.0, "max":1.0, "step":0.01}

    //@input float delayBeforeStop = 1.5 {"widget":"slider", "min":0.0, "max":3.0, "step":0.01}

     

    //@input SceneObject objectWithTweens

    //@ui {"widget":"group_end"}

     

     

    var bubblePass = script.bubble.mainMaterial.mainPass;

     

    var n = script.image.length;

    var image = script.image;

    var curIndex = -1;

     

    var tapTrigger = script.createEvent("TouchStartEvent");

    tapTrigger.bind(randomizeStart);

     

    var updateEvent = script.createEvent("UpdateEvent");

    updateEvent.bind(updateFunc);

     

    function randomizeStart() {

    // Stop tweening the default image

    global.tweenManager.stopTween(script.objectWithTweens, "ALPHA");

    global.tweenManager.startTween(script.objectWithTweens, "ALPHA-100");

     

    // start randomizing, disable user input

    randomizeStartTime = getTime();

    updateEvent.enabled = true;

    tapTrigger.enabled = false;

    }

     

    function updateFunc() {

    var curTime = getTime();

     

    // If still choosing random image

    if ((curTime - randomizeStartTime) < script.delayBeforeStop) {

    if ((curTime - setImageTime) > script.delayBetweenImages) {

     

    // Prevent selecting the same image twice

    var index = randomInt(n);

    var i = 0;

    while (index == curIndex && i < 10) {

    index = randomInt(n);

    i++;

    }

     

    setImageTime = curTime;

     

    // Set the displayed image to the selected texture

    bubblePass.baseTex = image[index];

    curIndex = index;

    }

    } else {

    // Play a tween when we've chosen an image'

    if ((curTime - randomizeStartTime) > script.delayBeforeStop - 0.4) {

    global.tweenManager.startTween(script.objectWithTweens, "SCALE");

     

    global.behaviorSystem.sendCustomTrigger ("play_" + curIndex);

    }

     

    // Enable user input once we've chosen an image'

    updateEvent.enabled = false;

    tapTrigger.enabled = true;

    }

    }

     

    function randomInt(val) {

    return Math.floor(Math.random() * Math.floor(val));

    }

     

    function init() {

    setImageTime = 0;

    randomizeStartTime = -1;

    bubblePass.baseTex = script.defaultTex;

     

    // Add some effect so the Lens feels dynamic before the user starts playing

    global.tweenManager.startTween(script.objectWithTweens, "ALPHA");

     

    updateEvent.enabled = false;

    }

     

    init()

     

     

    Comment actions Permalink

We're here to help! We just need a little bit of information...

What system are you using?

Have you downloaded the latest version of Lens Studio?

Please download the latest version of Lens Studio. If you still run into this issue, please come back and report it!

Is this issue causing Lens Studio to crash?

What system do you run Lens Studio on?

Version

Graphics

Follow the next steps to help us solve your issue:

  • Copy and paste this text into your TerminalCommand Window
    open ~/Library/Preferences/Snap/Lens\ Studio/ %LOCALAPPDATA%\Snap\Lens Studio Copy Text
  • Press ReturnEnter to run the command. The Lens Studio folder will automatically open
  • Prepare to upload your files: zip the "Log" Folder by right-clicking and choosing "compress."
    Locate the Log.txt file right above it.

    Attach a screenshot of the issue:

Name:

Email:

What is this most relevant to?

Please enter a brief description of your issue:

Thanks for submitting this issue.

Unfortunately, it's likely due to the operating system or hardware you're using – since they don't meet the system requirements for Lens Studio.

Still, we hear you loud and clear, and are logging the issue in case there's ever a workaround we can provide!

Minimum Requirements

Operating System: Windows 10 (64 bit); MacOS 10.11+

Hardware: Minimum of Intel Core i3 2.5Ghz or AMD Phenom II 2.6Ghz with 4 GB RAM; Intel HD Graphics 4000 / Nvidia GeForce 710 / AMD Radeon HD 6450 or better; screen resolution of 1280x768 or higher

We'll try to resolve this issue as soon as possible. Thanks for letting us know about it!

Keep an eye out for a followup email from us. We may have a couple more questions for you, or we might already have a solution to offer.

Happy creating!