Troubles with colors

Hello, i've got  a problem with render state



I ve got 5 SimpleDiceUI object in the scene and only the second one should be animate with a red light on it but the others are also in red except the first.



Here is my test object


package bombastic;

import java.util.logging.Level;
import bombastic.jme.SimpleDiceUI;
import com.jme.app.SimpleGame;
import com.jme.util.LoggingSystem;

public class Test extends SimpleGame
{
   SimpleDiceUI[] dices=new SimpleDiceUI[5];

   public static void main(String[] args)
   {
      Test app = new Test();
      app.setDialogBehaviour(
         SimpleGame.FIRSTRUN_OR_NOCONFIGFILE_SHOW_PROPS_DIALOG);
      LoggingSystem.getLogger().setLevel(Level.OFF);
      app.start();
   }

   protected void simpleInitGame()
   {
      for (int i=0;i<dices.length;i++)
         dices[i] = new SimpleDiceUI(rootNode,2*i,0);

      lightState.setEnabled(false);
      rootNode.updateRenderState();
   }

   protected void simpleUpdate()
   {
      dices[1].blink(0);
   }   
}




and here is my DiceUIObject


package bombastic.jme;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL;

import com.jme.image.Texture;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.state.AlphaState;
import com.jme.scene.state.RenderState;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;
import com.jmex.model.XMLparser.JmeBinaryReader;
import com.jmex.model.XMLparser.Converters.MilkToJme;

public class SimpleDiceUI
{
   private static int id;

   //UI Data
   private Node _boardRootNode;
   private Node _objRoot;
   private Node _diceModel;
   private int _initial_x;
   private int _initial_y;
   
   private boolean _blinkInitialised=false;
   private boolean _isInitialised=false;
   private boolean _lighted=false;
   private int _spendTime;
   private int _firstBlinkTime;
   private Box _blinkedBox=null;
   
   public SimpleDiceUI(Node rootNode,int x,int y)
   {
      _initial_x=x;
      _initial_y=y;
      _boardRootNode=rootNode;
      _objRoot = new Node("DiceUI_"+id++);
      init(0);
   }
   
   public void init(float time)
   {
      if (!_isInitialised)
      {
         _isInitialised=true;
         _diceModel = loadDiceModel();
         _objRoot.attachChild(_diceModel);
         prepareBlinkEffect(_objRoot);
         _objRoot.updateRenderState();
         _boardRootNode.attachChild(_objRoot);
         _objRoot.setLocalTranslation(new Vector3f(_initial_x,_initial_y,1));
         _objRoot.updateGeometricState(time,false);
         _objRoot.updateRenderState();
      }
   }

   private Node loadDiceModel()
   {
      Node diceNode=null;

      // Load Dice Model
      MilkToJme converter=new MilkToJme();
      ByteArrayOutputStream BO=new ByteArrayOutputStream();   
      URL textu=DiceUI.class.getClassLoader().getResource("models/dice.bmp");
      URL diceModel=DiceUI.class.getClassLoader().getResource("models/dice.ms3d");
      
      try
      {
         converter.convert(diceModel.openStream(),BO);
      } catch (IOException e) {
         System.out.println("damn exceptions:" + e.getMessage());
      }
      JmeBinaryReader jbr=new JmeBinaryReader();
      try
      {
         diceNode=jbr.loadBinaryFormat(new ByteArrayInputStream(BO.toByteArray()));
      } catch (IOException e) {
         System.out.println("damn exceptions:" + e.getMessage());
      }
      
      // create texture
      TextureState ts =
         DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
      ts.setEnabled(true);
      Texture texture =
         TextureManager.loadTexture(
            textu,
            Texture.MM_LINEAR,
            Texture.FM_LINEAR);
      ts.setTexture(texture);

      diceNode.setRenderState(ts);
      TextureManager.releaseTexture(texture);

      return diceNode;      
   }

   private void prepareBlinkEffect(Node node)
   {
      System.out.println("prepareBlinkEffect");
      _blinkedBox = new Box("RedBox", new Vector3f(0, 0, 0), .5f, .5f, .5f);
      _blinkedBox.setLocalScale(.97f);
      _blinkedBox.setSolidColor(new ColorRGBA(0.8f, 0.5f, 0.5f, 0.5f));

      AlphaState as =   DisplaySystem.getDisplaySystem().getRenderer().createAlphaState();
      as.setBlendEnabled(true);
      _blinkedBox.clearRenderState(RenderState.RS_ALPHA);
      node.setRenderState(as);

      node.attachChild(_blinkedBox);
      _blinkedBox.updateRenderState();
      as.setEnabled(true);
      node.updateRenderState();
   }
   
   
   public void blink(float time)
   {
      boolean change = false;
      int life = 200;
      
      if(!_blinkInitialised)
      {
         // initialise blink
         _firstBlinkTime=(int)System.currentTimeMillis();
         _spendTime =0;
         _blinkInitialised=true;
         change =true;
         
         // make the color box appears
         _blinkedBox.setLocalScale(1.02f);
      }
      else
         _spendTime = (int)System.currentTimeMillis()- _firstBlinkTime;
      
      if(life < _spendTime)
      {
         _spendTime = 0;
         _firstBlinkTime=(int)System.currentTimeMillis();
         change=true;
      }

      if(change)
      {
      
         if (!_lighted)
         {
            _objRoot.setLocalScale(1.1f);
            _lighted=true;         
         }
         else
         {
            _objRoot.setLocalScale(1.0f);
            _lighted=false;               
         }
      }
   }
}



Can somebody help me ? I'm becoming mad !!!

Define a render state for the other spatials (e.g. in the rootNode) of the same kind you are using for blinking (alpha in this case). OpenGL uses the last renderstate if no new renderstate (of a special kind) is set to draw an object.

Thanks for your quick response, it works fine now.  :wink: