Created
March 8, 2019 17:53
-
-
Save thelucre/169a69169a75c06b329ae601906105d3 to your computer and use it in GitHub Desktop.
Touch Interaction test for Snapchat Lens Studio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -----JS CODE----- | |
// Code runs runs during the `Initialized` event | |
// Properties set out of function scope are per-instance values | |
var isVisible = true; | |
var so = script.getSceneObject(); | |
var mesh = so.getComponentByIndex("MeshVisual", 0); | |
var mat = mesh.getMaterial(0).clone(); | |
// Setup instances of a material | |
mesh.clearMaterials(); | |
mesh.addMaterial(mat); | |
// Main event logic in callback | |
function onTouchEnd(eventData) { | |
isVisible = !isVisible; | |
// Fire off a tween rather than setting material colors explicilty | |
global.tweenManager.startTween(script.getSceneObject(), "box_alpha"); | |
// OLD: Set material colors explicitly | |
// var color = mat.getPass(0).baseColor; | |
// color.a = isVisible ? 1.0 : 0.0; | |
// mat.getPass(0).baseColor = color; | |
} | |
// Register the events to listen to | |
var touchEvent = script.createEvent("TouchEndEvent"); | |
touchEvent.bind(onTouchEnd); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment