0
\$\begingroup\$

I am pretty new to game dev (and libgdx + scene2d specifically), I am creating a dialog system for an rpg game and obviously a dialog window has a close button to close a dialog but for some reason it takes few clicks to close it (see video).

I have added System.out.println(Actor.class) to where the listener executes:

Events fired as planned

As you can see the events fired as planned!

Here is my listener code:

closeButton.addListener(new ChangeListener() {

  @Override
  public void changed(ChangeEvent event, Actor actor) {
    System.out.println(Actor.class);
    event.getListenerActor().getParent().addAction(Actions.hide());        
  }
});

Please send help, thank you

\$\endgroup\$
1
\$\begingroup\$

Guys who recommended checking whether stage.act() is firing properly were correct!

This is my original code in Hud.java(the class that renders the hud layer where I try to display dialogs):

  public void render(float delta) {
        stage.act(delta);
        stage.draw();
    } 

And this is the code that fixed it:

public void render(float delta) {
    stage.draw();
    stage.act(delta);
}

It was a simple mistake, my bad, it is only logical to draw your things and then update them.

Thanks everyone for the imput

\$\endgroup\$
0
\$\begingroup\$

I think you should use ClickListener:

    closeButton.addListener(new ClickListener() {

    @Override
    public void clicked(InputEvent event, float x, float y) {
        System.out.println(Actor.class);
        event.getListenerActor().getParent().addAction(Actions.hide());             
    }

});

Also, check if you call method stage.act() in render. Without that action will not work. Eventually you can use setVisible(false) on actor.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks, but it didn't work. I googled prior to asking this here, community seems to have a hard time deciding weather its clicklistener or changelistener after all \$\endgroup\$ – DRONE_6969 Jul 7 '18 at 2:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.