Reputation:
I never used the checkbox of libGDX before, and I don't know how to start implementing it in a proper way to Android.
I want to change some things when the checkbox is set to true and change other things when it is set to false. Do I need to make if (checkbox.isChecked()) {...} else{...}
at render()
? or I need to add a ChangeListener
to my checkBox? or a InputListener
? or none of these? or all of these? (just kidding in the last question)
Upvotes: 1
Views: 2336
Reputation: 2465
This depends on what you want the checkbox to do. Most times you will want to use a listener to handle any sort of user input.
For example, if you want to show extra forms to a user when the check a box you only want to create / delete those forms once (on the corresponding check / uncheck actions).
Here is an official example of use for a checkbox listener:
checkBox.addListener(new ChangeListener() {
@Override
public void changed (ChangeEvent event, Actor actor) {
Gdx.graphics.setContinuousRendering(checkBox.isChecked());
}
});
Source: https://github.com/libgdx/libgdx/blob/master/tests/gdx-tests/src/com/badlogic/gdx/tests/UITest.java (Good for all types of UI elements in libgdx)
Upvotes: 3