Multiple Billboard Animations in a Row

  • hey Julien
    check out this article

    https://lensstudio.zendesk.com/hc/en-us/community/posts/115020451643-Make-Things-Change-on-Tap?page=1#community_comment_360000037943

     

    it will may help with. the tap going through the "array" re the "right position" look at this

    https://lensstudio.snapchat.com/guides/general/tracking-modes/

    Comment actions Permalink
  • Hi Julien! Patrick is right, looping through an array is the best way to do this. I created a script for you that should do what you want. It's modified from another post I posted re: tapping billboards to support and array of billboards and sounds. 

    https://lensstudio.zendesk.com/hc/en-us/community/posts/360000035023-Tap-to-Trigger-Billboard-and-Sound

    It supports a variable array so you can add as many as you'd like!

    Add the script to an empty object running on the "Initialized" event. Then, fill the arrays with what you want to toggle through on tap. 

    // -----JS CODE-----
    // @input Component.SpriteVisual[] billboardSprite
    // @input Component.AudioComponent[] audioComponent

    var audioComponent = null;
    var currIndex = 0;

    function onTurnOn( eventData )
    {
    global.touchSystem.touchBlocking = true;
    global.touchSystem.enableTouchBlockingException("TouchTypeDoubleTap", true);
    global.touchSystem.enableTouchBlockingException("TouchTypeSwipe", true);

    for( var i = 0; i < script.billboardSprite.length; i++ ) {
    script.billboardSprite[i].enabled = false;
    }
    }
    var turnOn = script.createEvent("TurnOnEvent");
    turnOn.bind(onTurnOn);

    function onTap( eventData )
    {
    for( var i = 0; i < script.billboardSprite.length; i++ ) {
    script.billboardSprite[i].enabled = false;
    }

    for( var i = 0; i < script.audioComponent.length; i++ ) {
    script.audioComponent[i].stop(false);
    }

    currIndex++;
    if( currIndex >= script.billboardSprite.length ) {
    currIndex = 0;
    }

    // Show billboard
    if( script.billboardSprite[currIndex] )
    {
    script.billboardSprite[currIndex].enabled = true;

    // Play animation
    var control = script.billboardSprite[currIndex].getMaterial(0).getPass(0).baseTex.control;
    if( control && control.play )
    {
    control.play(1, 0.0);
    }
    }

    // Play sound
    if( currIndex < script.audioComponent.length && script.audioComponent[currIndex] )
    {
    script.audioComponent[currIndex].play( 1 );
    }
    }
    var tap = script.createEvent("TapEvent");
    tap.bind(onTap);
    Comment actions Permalink
  • Hey Travis,

    The script is working but the values are kinda messed up.
    Maybe you made a mistake. The script is taking Value 1 first then Value 0 and then Value 2?

    Could you fix that in your script?

     EDIT:

    Could you maybe also post a script that does the same but not using billboard but Component.PostEffectVisual please?

    Thank you

    Comment actions Permalink
  • Hi Julien, rewrote to fix the starting problem. The fix was easy, just initialize currIndex to -1. Then, I made it support general SceneObjects instead of billboard specifically. Basically, you can now feed anything into the array including post effect objects. 

    // -----JS CODE-----
    // @input SceneObject[] sceneObjects
    // @input Component.AudioComponent[] audioComponents

    var audioComponent = null;
    var currIndex = -1;

    function onTurnOn( eventData )
    {
    global.touchSystem.touchBlocking = true;
    global.touchSystem.enableTouchBlockingException("TouchTypeDoubleTap", true);
    global.touchSystem.enableTouchBlockingException("TouchTypeSwipe", true);

    for( var i = 0; i < script.sceneObjects.length; i++ ) {
    script.sceneObjects[i].enabled = false;
    }
    }
    var turnOn = script.createEvent("TurnOnEvent");
    turnOn.bind(onTurnOn);

    function onTap( eventData )
    {
    for( var i = 0; i < script.sceneObjects.length; i++ ) {
    script.sceneObjects[i].enabled = false;
    }

    for( var i = 0; i < script.audioComponents.length; i++ ) {
    script.audioComponents[i].stop(false);
    }

    currIndex++;
    if( currIndex >= script.sceneObjects.length ) {
    currIndex = 0;
    }

    // Show scene object
    if( script.sceneObjects[currIndex] )
    {
    script.sceneObjects[currIndex].enabled = true;
    }

    // Play sound
    if( currIndex < script.audioComponents.length && script.audioComponents[currIndex] )
    {
    script.audioComponents[currIndex].play( 1 );
    }
    }
    var tap = script.createEvent("TapEvent");
    tap.bind(onTap);
    Comment actions Permalink
  • Thank you very much!

    Comment actions Permalink
Have a comment?

Please sign in to leave a comment.

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!