Fading in/out a text

Hi, I am trying to do an effect of fading to text (this text has been created using Text class), I have used to do this the class FadeInOut and FadeInOutController, but it doesn't work, although with an image it does. How I can get the same effect  on the text.


//Create FadeInOut
logoQuad_fadeInOut = CreateFade(logoQuad, "logQuad");
txtObj_fadeInOut = CreateFade(txtObj, "txtObj");

//Function CreateFade
private FadeInOut CreateFade(Geometry object, String name){
      FadeInOut f = new FadeInOut( name, object, null, null, new ColorRGBA(1, 1, 1, 0), 0.3f);
      return f;
}

//Create Controller
logoQuad_fadeInOutController = new FadeInOutController(logoQuad_fadeInOut);
txtObj_fadeInOutController = new FadeInOutController(txtObj_fadeInOut);
      
//Add Controller
logoQuad.addController(logoQuad_fadeInOutController);
txtObj.addController(txtObj_fadeInOutController);



The logoQuad fades, but txtObj does anything.

I wonder if you have a lightstate somehow attached to your text_obj…



How is it attached to the scene?

No i have nothing like that.



This is my txtObj


txtObj = CreatePresenta();

private Text CreatePresenta(){      
        // Create presenta 
      TextureState tsFont;
      Text text;
        tsFont = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
        tsFont.setTexture(TextureManager.loadTexture(
              IntroMenuState.class.getClassLoader().getResource("res/gameFont.png"),
               Texture.MinificationFilter.BilinearNearestMipMap,
               Texture.MagnificationFilter.Bilinear));
        text = new Text("text", "Presenta:");
        text.setLocalTranslation(650, 100, 0);
        text.setZOrder(0);
        text.setRenderState(tsFont);
        text.setLocalScale(3f);
        text.setTextColor(ColorRGBA.black);
        return text;
   }



And it is attached just like that: getRootNode().attachChild(txtObj);

decrement a float value "textAlpha" in your update loop from 1 to 0 and then set the alpha value:


textObj.getTextColor().a = textAlpha;

I did it, i only want to know if there is another way to get the same, using a controller. Thanks.

yes you can do the same in a controller, just extend Controller, set your values in the constructor (targetalpha, speed, …) and set the alpha value of the text in the overridden update method.

Alternatively you could just set the ColorRGBA reference to both objects (just set the defaultColor() to the same ColorRGBA object)…