Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextButton LibGDX only clicks once

Tags:

java

libgdx

I'm coding a libGDX application that uses a button. The button looks like this:

TextButton btnPrint = new TextButton( "Print", skin );
btnPrint.setClickListener( new ClickListener() {
    @Override
    public void click(Actor actor,float x,float y )
    {
        System.out.println("Printing...");

    }
} );

When I click the button, it prints"Printing..." as expected, however, if I click it again, it does nothing. How can I fix that?

like image 261
Jordan Goulet Avatar asked Jul 13 '26 15:07

Jordan Goulet


1 Answers

Out of my head but try:

btnPrint.addListener(new ClickListener() {
    @Override
    public void clicked(InputEvent event, float x, float y)
    {
        System.out.println("Printing...");
    }
});

Everything used here comes from the LibGDX library so import the correct classes. Perhaps you are using vis-ui, AWT, JavaFX or anything else? I find it mysterious that your code is compiling correctly.

like image 190
Madmenyo Avatar answered Jul 15 '26 04:07

Madmenyo