class ObjectBehavior extends Sup.Behavior {
  hueStart : number
  hueEnd : number

  update() {
    let light = Sup.getActor("Light");
    let lightHue = light.spriteRenderer.getColor().getHSL().h;
    let hidden;
    
    if (this.hueStart < this.hueEnd) {
      hidden = (this.hueEnd/360 >= lightHue) && (this.hueStart/360 <= lightHue);
    }
    else {
      let newLightHue = (lightHue < this.hueStart) ? (lightHue + 1) : lightHue;
      let newHueEnd = this.hueEnd + 360;
      
      hidden = (newHueEnd/360 >= newLightHue) && (this.hueStart/360 <= newLightHue);
    }
    
    if (this.actor.arcadeBody2D) {
      this.actor.arcadeBody2D.setEnabled(hidden);
    }
    else {
      this.actor.getChildren().map(child => { if (child.arcadeBody2D) child.arcadeBody2D.setEnabled(hidden) });
    }
    this.actor.setVisible(hidden);
  }
}
Sup.registerBehavior(ObjectBehavior);
