Skip to content

Instantly share code, notes, and snippets.

@inear
Created October 16, 2017 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inear/c962cfb452602d8c652454bb1630936e to your computer and use it in GitHub Desktop.
Save inear/c962cfb452602d8c652454bb1630936e to your computer and use it in GitHub Desktop.
lightController
// -----JS CODE-----
// @input float duration
// @input Component.SpriteVisual light1
// @input Component.SpriteVisual light2
// @input Component.SpriteVisual light3
var lights = [self.light1,self.light2,self.light3];
var mouthEvent = self.script.createEvent("MouthWasJustOpenedEvent");
var totalTime = 0.0;
mouthEvent.bind(function(eventData)
{
self.script.removeEvent(mouthEvent);
startLoop();
})
function startLoop(){
var updateEvent = self.script.createEvent("UpdateEvent");
updateEvent.bind(function(event) {
totalTime += event.getDeltaTime();
if(totalTime > 2 ){
totalTime = 0;
}
for(var i=0; i<3; i++){
var initialWait = i*0.3;
var offsetTime = totalTime-initialWait;
var light = lights[i];
if (offsetTime > initialWait && offsetTime < initialWait + self.duration)
{
var c = (offsetTime - initialWait) / self.duration ;
var clr = light.mainPass.baseColor;
clr.a = easeInOutCubic(c);
light.mainPass.baseColor = clr;
light.getSceneObject().enabled = true;
}
else if (offsetTime > self.duration+initialWait)
{
// self.obj.enabled = false;
var clr = light.mainPass.baseColor;
clr.a += (.2-clr.a)*0.4;
light.mainPass.baseColor = clr;
//initialWait = self.wait * 2.0;
}
}
});
}
var easeInOutCubic = function (t) { return t<.5 ? 4*t*t*t : (t-1)*(2*t-2)*(2*t-2)+1 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment