The forum on this site is closed for new comments and posts. Continue the conversation in the new forum, and learn more here.

Trying to get a 2d animation to start on tap

  • Hi Ryan!

    You're close. You can actually just use the play function on controllerProvider to play your animation!

    play(Number loops, Number offset) 

    so something like: 

    function activateSnowmanAnimation () {
    controllerProvider.play(1,0);
    }

    Take a look at https://lensstudio.snapchat.com/api/classes/AnimatedTextureFileProvider/ for more information .

     

    By the way, if you haven't check out the Fullscreen Template. It contains similar functions to help you play 2d or 3d animation, as well as other features such as enabling and disabling sounds and object. https://lensstudio.snapchat.com/templates/world/fullscreen-template/

     

    Can't wait to see what you make!

    Jon

     

     

    Comment actions Permalink
  • Thank you so much. That worked, but now it's at the end frame before the tap. Once it's tapped, it plays through the animation. Is that something I would have to change in the number loops and offset? 

    Comment actions Permalink
  • Hi Ryan,

    You can use something like setOnFinish to call a function when the animation end and set it to go back to frame 0 then.

    Something like: 

    controllerProvider.setOnFinish(function() {controllerProvider.pauseAtFrame(0)})


    Let me know if this works for you.

     

    Cheers!

    Jonathan

    Comment actions Permalink
  • Hi John, 

     

    So the tap works, but when the project is loaded, it starts at the end frame. Is there a way to set it so when someone loads the project, the animation is on the first frame? 

     

    Thank you,

    Ryan

    Comment actions Permalink
  • Hi,

    I have the exact same question / problem.  I have almost zero scripting knowledge, so am relying on templates to make things work.  I'm using a FaceTriggerAnim script, with trigger set to "Tap" to launch a 2D animation.  This works fine--the animation plays when tapped--but the last frame of the animation is on screen even before the tap.

    I've looked at the Fullscreen template as well--but still get the same issue with the last frame starting onscreen before the tap triggers it.

    Any help / suggestions hugely appreciated!

     

    Ben

    Comment actions Permalink
  • Hi Ryan, Ben,

    You can do this by calling 

    controllerProvider.pauseAtFrame(0)

    on a script running on initialized.

     

    In the case of FaceTriggerAnim script, you can edit this script (In the Resources panel , under Scripts, select FaceTriggerAnim). and add the following at the bottom of the file:

    for (var i = 0; i < script.play2dSprites.length; i++)
    {
    if (script.play2dSprites[i]
    && script.play2dSprites[i].mainPass.baseTex
    && script.play2dSprites[i].mainPass.baseTex.control
    && script.play2dSprites[i].mainPass.baseTex.control.play)
    {
    var controllerProvider = script.play2dSprites[i].mainPass.baseTex.control;

    // Start at frame 0 when Lens initializes
    controllerProvider.pauseAtFrame(0);

    // Go back to frame 0 everytime animation finishes
    controllerProvider.setOnFinish(function() {controllerProvider.pauseAtFrame(0);});

    }
    }

    What we're doing here is going through all the sprites we added in the Inspector panel, and telling each of them to start at frame 0, and on animation end, go back to frame 0.

    Optional: feel free to remove the line below the comment describing which feature you want to disable. 

     

    Let me know if I can further clarify. Can't wait to see what you make!

     

    Jon

    Comment actions Permalink
  • Hi Jon,

    Thanks very much for the input--it kind of makes sense!

    I actually got things working from within the Fullscreen template using the FullscreenTemplateState script.  I'd tried this previously, though, and not succeeded.  Not even 100% sure what I did differently to make it work!

    Thanks again for the feedback.

     

    Ben

    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!