Skip to content

Instantly share code, notes, and snippets.

@seanirby
Created August 1, 2016 21:28
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 seanirby/50ccf8c32fe1b1dcf1e88495342962ce to your computer and use it in GitHub Desktop.
Save seanirby/50ccf8c32fe1b1dcf1e88495342962ce to your computer and use it in GitHub Desktop.
class BlinkManager {
constructor(displayObj, changeFunc1, changeFunc2, changeFuncEnd, rate, duration){
this.displayObj = displayObj;
this.changeFuncEnd = changeFuncEnd;
this.duration = duration;
this.rate = rate;
this.blinkCount = 0;
this.totalCount = 0;
this.last = changeFunc2;
this.next = changeFunc1;
this.complete = false;
}
tick(){
if(this.totalCount >= this.duration){
this.changeFuncEnd.call(this.displayObj);
this.complete = true;
} else {
let game = this.displayObj.game;
let elapsed = game.time.elapsedMS;
this.blinkCount += elapsed;
this.totalCount += elapsed;
if(this.blinkCount >= this.rate){
this.blinkCount = this.blinkCount % this.rate;
this.next.call(this.displayObj);
this.last = [this.next, this.next = this.last][0];
}
}
}
isComplete(){
return this.complete;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment