Created
October 16, 2017 05:05
-
-
Save inear/c962cfb452602d8c652454bb1630936e to your computer and use it in GitHub Desktop.
lightController
This file contains hidden or 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----- | |
// @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