I am trying to make the Image hidden then fade in and this is working but the background image is also become hidden the fade in : here where I apply the action in this class:

   public class MainButtons {
    public Viewport viewport;
    public Stage stage;
    public boolean centerPressed;

    public Image fire;
    public Image center;
    public Sound flap;

    public OrthographicCamera camera;
    public static Table table;

    public MainButtons(SpriteBatch spriteBatch) {
        camera = new OrthographicCamera();
        viewport = new StretchViewport(KidTele.V_WIDTH,KidTele.V_HIEGH,camera);
        stage = new Stage(viewport, spriteBatch);
        //InputMultiplexer this is why only input handling  from controller
        flap= Gdx.audio.newSound(Gdx.files.internal("one.mp3"));

        fire= new Image(new Texture("cars/fire.png"));

        //buttonone.setSize(10, 5);


    public void defineCenter()
        center=new Image(new Texture(Gdx.files.internal("0.png")));

        center.setBounds(viewport.getWorldWidth() / 5f, viewport.getWorldHeight() / 3f, viewport.getWorldWidth() / 1.5f, viewport.getWorldHeight() / 3f);
        center.addListener(new InputListener() {
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                centerPressed = true;
                return true;

            public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
                //center.addAction(Actions.sequence(Actions.rotateTo(360, 2), Actions.fadeIn(1)));
                center.addAction(Actions.sequence(Actions.fadeOut(1), Actions.fadeIn(1)));
                centerPressed = false;
    public void draw() {
    public void resize(int width, int height) {
        viewport.update(width, height);

and this is the code of the screen:

public class PlayScreen implements Screen {
    private KidTele game;
    private OrthographicCamera gamecam;
    private Viewport gameport;
    private World world;
    private Box2DDebugRenderer b2dr;
    private MainButtons mainButtons;
    private Texture background;
    private Sound flap;
    public PlayScreen(KidTele game)
        gamecam=new OrthographicCamera();
        gameport=new StretchViewport(KidTele.V_WIDTH,KidTele.V_HIEGH,gamecam);
        //stage=new Stage(gameport,((KidTele) game).batch);
        background=new Texture("background2.png");
        b2dr=new Box2DDebugRenderer();
        world=new World(new Vector2(0,0.8f),true);
        flap= Gdx.audio.newSound(Gdx.files.internal("one.mp3"));
        mainButtons=new MainButtons(game.batch);
    public void show() {

    public void handleinput(float dt)

        if(Gdx.input.isKeyJustPressed(Input.Keys.BACK)) {
            game.setScreen(new PlayScreen(game));

    public void update(float dt)
        world.step(1 /60f, 6, 2);


    public void render(float delta) {

        Gdx.gl.glClearColor(1, 1, 1, 1);

         b2dr.render(world, gamecam.combined);


        game.batch.draw(background, 0, 0, gameport.getWorldWidth(), gameport.getWorldHeight());

    public void resize(int width, int height) {
        gameport.update(width, height);
        mainButtons.resize(width, height);

Also when I apply the rotation Action (which is commented) it rotates the image only one time although I put it on the event Touchup, while the fading in and out is applied on each touch but fading applied on image and background

  • \$\begingroup\$ What type of actor is center? If it is your own subclass could you post your draw code? \$\endgroup\$ Jun 29, 2016 at 21:41
  • \$\begingroup\$ I edited the code and added some explantation \$\endgroup\$ Jun 29, 2016 at 22:18

1 Answer 1


Set batch color to default every frame. This is partial solution.

public void render(float delta) {
    batch.setColor(1, 1, 1, 1);
    // ...

In case of your (stage) example:

public void draw() {
    stage.getBatch().setColor(1, 1, 1, 1); //add this line

Also sometimes is good to set Actions.alpha(0) at start of animation.

center.addAction(Actions.sequence(Actions.alpha(0), Actions.fadeOut(1), Actions.fadeIn(1)));  //Used in LibGDX dialog.show method

Another source: https://stackoverflow.com/questions/38113003/libgdx-actions-to-image-is-applied-to-whole-actors


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .