Libgdx 按下文本按钮后,如何使其淡出?

Libgdx 按下文本按钮后,如何使其淡出?,libgdx,Libgdx,我只是想淡出(不透明度=完全透明)按钮后,我按下它。。。下面的代码有一种无法解释的效果:背景图像(完全不同的演员!)变为黑色 我做错了什么 Skin skin = new Skin(); TextureAtlas buttonAtlas = new TextureAtlas(Gdx.files.internal("gfx/menu_buttons.pack")); skin.addRegions(buttonAtlas); TextButtonSt

我只是想淡出(不透明度=完全透明)按钮后,我按下它。。。下面的代码有一种无法解释的效果:背景图像(完全不同的演员!)变为黑色

我做错了什么

      Skin skin = new Skin();
      TextureAtlas buttonAtlas = new TextureAtlas(Gdx.files.internal("gfx/menu_buttons.pack"));
      skin.addRegions(buttonAtlas);
      TextButtonStyle textButtonStyle = new TextButtonStyle();
      textButtonStyle.font = mButtonSpacefont;
      textButtonStyle.up = skin.getDrawable("menu_button_background_top");
      textButtonStyle.down = skin.getDrawable("menu_button_background_bottom");
      mButtonStartGame = new TextButton("Play", textButtonStyle);
      mButtonStartGame.setPosition(game.getIdealWidth()/2 - mButtonStartGame.getWidth()/2,
            game.getIdealHeight()/2 - mButtonStartGame.getHeight()/2);

      mButtonStartGame.addListener(new ChangeListener()
      {
         @Override
         public void changed (ChangeEvent event, Actor actor)
         {
            //triggers when button is pressed and let go
            mButtonStartGame.addAction(Actions.fadeOut( 1.0f ));
          }
      });

      // add actors to stage
      mStage.addActor(backgroundActor);//background
      mStage.addActor(titleActor);//ontop of background
      mStage.addActor(mButtonStartGame);//ontop of background
更新1: 我发现文本按钮是淡出的-但是-包含背景图像的演员也是淡出的
backgroundActor
!当代码甚至没有调用
backgroundActor.addAction(Actions.fadeOut(1.0f)),为什么backgroundActor会褪色

更新2:
render()
方法似乎在。。。当我调用
Gdx.gl.glClearColor(0,0,0,0)时由于淡出操作,整个屏幕(滴定器除外!)变为黑色。当我调用
Gdx.gl.glClearColor(1,1,1,1)时整个屏幕(标题器除外!)变为白色

@Override
public void render(float delta)
{
    Gdx.gl.glClearColor(0, 0, 0, 0);//clear the screen black
    //Gdx.gl.glEnable(GL20.GL_BLEND);// no effect, so commented out
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    // update the actors
    mStage.act(Gdx.graphics.getDeltaTime());

    // draw the actors
    mStage.draw();
}

解决方案是,我的演员需要考虑
parentAlpha
,并使用
batch.setColor()
设置颜色。 因为我的背景是一名演员,而且我没有设置批次颜色,所以背景被弄糟了

例如:

public class ActorBackground extends Actor
{
    // Member Variables
    private Texture mTexture;

    // Constructor
    public ActorBackground(GFXLoader gfxloader)
    {
        mTexture = new Texture(gfxloader.loadGraphic("menu_background"));// returns Gdx.files.internal(file.path())
        //setBounds(getX(), getY(), mTexture.getWidth(), mTexture.getHeight());
        setWidth(mTexture.getWidth());
        setHeight(mTexture.getHeight());
    }

    @Override
    public void draw(Batch batch, float parentAlpha)
    {
        // needed to make actions work
        super.act(Gdx.graphics.getDeltaTime());

        // needed to make fade work
        Color color = new Color(this.getColor().r, this.getColor().g, this.getColor().b, this.getColor().a * parentAlpha);
        batch.setColor(color);

        // show it
        batch.draw(mTexture, getX(), getY(), getWidth(), getHeight());
    }
}