Many of us modders tried to create lights that shut when the ship died. Problem is, using a simple check like this:
if (lightOn && lightsCheck.intervalElapsed()){
if (weapon.getShip() != null && weapon.getShip().isHulk()) {
weapon.getSprite().setColor(new Color (0,0,0));
weapon.getSprite().setAlphaMult(0);
lightOn = false;
}
}
leaves the light visible for no apparent reason. The simple workaround was to use a 2 frames animation with one empty frame and one frame on, or to force the sprite off every single frame... After several face-to-desk rages episodes, I found out that
the game set all weapons sprites color to (128,128,128) while hidden in the explosion cloud! And unfortunately for us, it don't do it immediately, overriding our scripts changes. But knowing this, the answer is simple, the script just need a delay to apply the modification AFTER the game darkened the sprite:
public class SCY_lightsEffect implements EveryFrameWeaponEffectPlugin
{
private boolean lightOn = true;
private boolean runOnce = true;
private final IntervalUtil lightsCheck = new IntervalUtil(0.5f, 1f);
private float range = 0;
@Override
public void advance(float amount, CombatEngineAPI engine, WeaponAPI weapon)
{
if (engine.isPaused() || !lightOn) {return;}
if (runOnce) {
weapon.getSprite().setAdditiveBlend();
runOnce = false;
}
lightsCheck.advance(amount);
if (lightsCheck.intervalElapsed()){
if (weapon.getShip() != null && weapon.getShip().isHulk())
{
range++;
if (range>1){
weapon.getSprite().setColor(new Color (0,0,0));
weapon.getSprite().setAlphaMult(0);
lightOn = false;
}
}
}
}
}