Skip to content

Instantly share code, notes, and snippets.

@thelucre
Created March 8, 2019 17:53
Show Gist options
  • Save thelucre/169a69169a75c06b329ae601906105d3 to your computer and use it in GitHub Desktop.
Save thelucre/169a69169a75c06b329ae601906105d3 to your computer and use it in GitHub Desktop.
Touch Interaction test for Snapchat Lens Studio
// -----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