Fullscreen Tapped Event (for iOS and Android)
Hi Lens creators! This quick guide explains how to setup fullscreen touches that work for both iOS and Android. To allow your Lens to respond to the "Tapped" event for fullscreen touches, you first need to tell the Snapchat user interface to ignore touches (allowing your Lens to take touch priority). You do this by enabling "Touch Blocking".
To enable fullscreen taps, first add the following script to your project bound to the "Initialized" event.
// The following script enables touch blocking which allows
// the tapped event to respond to fullscreen touches. It then
// enables touch blocking exceptions which allows Snapchat to
// still respond to certain types of inputs
global.touchSystem.touchBlocking = true;
global.touchSystem.enableTouchBlockingException("TouchTypeDoubleTap", true);
global.touchSystem.enableTouchBlockingException("TouchTypeSwipe", true);
This turns on "Touch Blocking" but still allows Snapchat to respond to double tap (to switch cameras) and swipe (to go to chat / stories) through touch blocking exceptions. IMPORTANT: Make sure the above script is bound to the "Initialized" event so it's enabled as soon as the Lens starts.
Next, add your fullscreen tap logic to a script bound to the "Tapped" event. For example, the below script toggles an object on and off when fullscreen tapped:
// @input SceneObject object
if( script.object.enabled )
{
script.object.enabled = false;
}
else
{
script.object.enabled = true;
}
Hey, can you give me the exact script so my billboard animation will start when I tap the screen?
Colin, first you need to follow the above to make the tapped event work properly on iOS. Then, create another script that actually does the animation playback. This script should then be bound to the "Tapped" event. This script should then go directly on your billboard object.
is there a way to override the double tap to swap cameras event? i'd like to make it so the user can tap multiple times in a row without the camera swapping.
Yep, just remove this line from the script in the post and it'll give the lens control of the Double Tap:
Hi Travis,
Thanks for putting up this guide! My team and I are facing a weird issue with Touch Blocking. Double Tap behaves as expected, but despite Touch Blocking on both Swipe and Pan, we cannot get fullscreen tap working and still allow the user to swipe to chat/stories.
We've tried implementing it as you have above
with and without a touch component (an invisible plane affixed to the camera)
using
using a Script Component set to "Tapped" event in LS as well as bound via script:
Same result every time. Double Tap swaps the camera. Tap executes the code just as intended. Swipe is completely ignored.
Wonder if you or anyone else might have some insight!
Thanks Much (:
~Naomi
Hi Naomi,
Thank you for your patience. I tried doing the following and my Lens seems to be able to get taps (in this case enabling and disabling objects), while still being able to swipe into discover and double-tapping to switch camera. I do not use an invisible plane affixed to the camera.
Here's my sample project. Let me know if you need any clarification or if I misunderstood your question.
Thank you!
Jonathan