Skip to content

Instantly share code, notes, and snippets.

@prestomation
Created March 5, 2019 05:31
Show Gist options
  • Save prestomation/dcbc02a3f61a27d411a609dd327070fd to your computer and use it in GitHub Desktop.
Save prestomation/dcbc02a3f61a27d411a609dd327070fd to your computer and use it in GitHub Desktop.
'use strict';
function setup(args, ctx) {
// This is a HTMLVideoElement that is powering the video texture for the current entity
// You can use any standard method on the Video element. See the docs here: https://developer.mozilla.org/en-US/docs/Web/API/HTMLVideoElement
// The following example uses the 'Space' key to toggle play/pause
ctx.video = ctx.entity.meshRendererComponent.materials[0].getTexture("DIFFUSE_MAP").image;
ctx.onKeyDown = (e) => {
switch(e.keyCode){
case sumerian.ScriptUtils.getKey("Space"):
if(ctx.video.paused) {
ctx.video.play();
}
else if(!ctx.video.paused) {
ctx.video.pause();
}
}
}
document.body.addEventListener('keydown', ctx.onKeyDown, false);
}
function cleanup(args, ctx) {
document.body.removeEventListener('keydown', ctx.onKeyDown, false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment