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

Combining the Fullscreen tap-through with swiping

  • Hi Bram! 

    Yes, this is possible. You just need to modify the FullscreenTemplateState.js inside the Scripts folder. 

    You'll notice that in this script, inside the function createTouchManager, we have an event that calls the following:

    if (getTime() > script.stateStartTime)
    {
        onStateEnd();
    }

    This is how the template knows to proceed to the next state. So, all we need to do, is call this using our own logic instead of on TouchStartEvent. 

    Let's say we want to proceed to the next state by swiping right. What we need to do is get where in the screen we started touching, and check that against where we ended. If where we ended is greater that where we started, then we have swiped right. We can replace our touchTapEvent with something like the following:

    var touchStartPos;

    var event = script.createEvent("TouchStartEvent");
    event.bind(function(eventData){
    touchStartPos = eventData.getTouchPosition();
    });

    var event = script.createEvent("TouchEndEvent");
    event.bind(function(eventData){
    if (touchStartPos) {
    var currentPos = eventData.getTouchPosition();
    var posChange = new vec2(currentPos.x - touchStartPos.x, currentPos.y - touchStartPos.y);

    if (posChange.x > 0) {
    print("Swiped Right");
    }
    }
    });

    Now that we can detect when the user swipes right, we can call tell the Lens to go to the next state when this happens.

    Putting it all together, our new createTouchManager looks something like:

    function createTouchManager () {

    var touchStartPos;

    var event = script.createEvent("TouchStartEvent");
    event.bind(function(eventData){
    touchStartPos = eventData.getTouchPosition();
    });

    var event = script.createEvent("TouchEndEvent");
    event.bind(function(eventData){
    if (touchStartPos) {
    var currentPos = eventData.getTouchPosition();
    var posChange = new vec2(currentPos.x - touchStartPos.x, currentPos.y - touchStartPos.y);

    if (posChange.x > 0) {
    print("Swiped Right");
    if (getTime() > script.stateStartTime)
    {
    onStateEnd();
    }
    }
    }
    });


    global.touchSystem.touchBlocking = true;
    global.touchSystem.enableTouchBlockingException("TouchTypeDoubleTap", true);
    global.touchSystem.enableTouchBlockingException("TouchTypeSwipe", true);
    }


    Don't forget to share with us what you end up making :)

    Cheers!

    Jon

    Comment actions Permalink
  • Jon, thanks again for an amazingly detailed answer. This is very helpful and opens up so many doors! I'm going to share a project file where this code has been implemented on the SnapLenses subreddit, to spread the word. Thanks again!

    Comment actions Permalink
  • Hello,

    instead of swiping, is it possible to end the state when touching a sprite?

     

    Thanks!

    Comment actions Permalink
  • Hi Cyrielle,

    By default, Fullscreen Template relies on Tap to advance to the next state. All we need to do is point it to a sprite so that it only listens to touches on that sprite rather than the whole screen. 

    To do this, all we need to do is to create a touch component. In the Objects panel, select your state. Then in it's Inspector panel, press Add Component > Touch.

    Since your sprite will be rendered on the Orthographic camera, set that to be your camera in the new Touch component. Finally, in the same component, press "Choose Mesh Visual" then select the Sprite that you want to use to trigger the next state. 

    Your should end up with something like this:

    Now, you will need to tap that sprite specifically to go to the next state.

    Let me know if you need any clarification. And as always, don't forget to share the result :)

     

    Cheers,

    Jon

    Comment actions Permalink
  • Hi Jon,

    Thx a lot! I was becoming crazy :)

    Another question... is it possible to add a state in order to go back to start?

     

    Cheers,

     

    Cyrielle

    Comment actions Permalink
  • Glad it was helpful! 

    By default, after the last state, you will be brought back to the first state. Is this not what you mean?

     

    Comment actions Permalink
  • Yep that’s exactly this!
    I wasn’t using the play tween on Start script si it didn’t ho black ton the first...
    But i’ m using a TweenAlpha on a facemask in once of the States...and this tween does’nt reset on end!
    During this state, i enable a face mask wich slowly disapaer with a tweenalpha script and a play tween on start...but when i go back to first state...my face mask doesn’t appear !

    Can you help me?

    Thx

    Comment actions Permalink
  • Hi Cyrielle!

    Are you adding your Face Mask to the On End > Disable Objects list on your state?

    With the Reset on End selected:

     

    I am able to get the mask to disappear:

     

    Let me know if this works for you :)

     

    Thanks,

    Jon

     

    Comment actions Permalink
  • Yeah!
    Thx a lot :)
    I tried a lot of combination but never worked! now it's ok

    If you can help on my last issue you'll be my SUPERMAN ;p

    Now i wan't to be able to enable a mask witch can disappear (like your exemple) but with a condition :

    When i touch button 1 this mask is enabled and disappear :

    and when i touch the button 2 this mask is enabled and disappear :

    Is it possible to do this?

     

    Thx a lot again !!!! 

     

    Cyrielle

     

    Comment actions Permalink
  • Hi Cyrielle,

    As the template name suggests, this template is aimed at fullscreen interactivity.

    If you're not tied to using the Fullscreen template, you can add a Touch component to your sprite so that it only detects touches on the sprite. 

    In the new touch component, assign Orthographic Camera as the Camera, and your Sprite as the Mesh Visual. 

     

    Now when you add a Script component on Touch, it will only be called if you touch the sprite!

    Then in this new script you can get a list of objects to enable and disable which will be called when the sprite is touched. Something like: 

    // @input SceneObject[] toEnable
    // @input SceneObject[] toDisable

    for (var i = 0; i < script.toEnable.length; i++) {
    script.toEnable[i].enabled = true;
    }

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

    Finally, you can list your face mask in the Inspector panel of the script:

     

    Let me know if you need any clarification!

    Can't wait to see the final result :) 

     

    Cheers,

    Jon

    Comment actions Permalink
  • Just a big THANK YOU !

    It works perfectly !!

    I can't wait to see the final result too :) but I still have a lot of issues to solve before having what i want to!!!

    I'm a rookie on LensStudio trying to do a pro lens.... Love Chalenges !

    Cheers,

     

    Cyrielle

    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!