Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Author Topic: About ships lights and how to shut them off  (Read 1239 times)

Tartiflette

  • Admiral
  • *****
  • Posts: 3529
  • MagicLab discord: https://discord.gg/EVQZaD3naU
    • View Profile
About ships lights and how to shut them off
« on: October 31, 2014, 05:43:36 AM »

Many of us modders tried to create lights that shut when the ship died. Problem is, using a simple check like this:

Code: java
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:

Code: java
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;
                }
            }
        }
    }   
}
Logged