About Libgdx Addlistener
Solution 1:
I would recommend to create a ClickListener
instead of an InputListener
and add it as usual. Inside of the Listener you check if the loading is done. If it's done you do what ever you want to do. If not you return without any action.
To give you an example how to add an ClickListener
to a TextButton which should already do your task:
TextButtonStylestyle=newTextButtonStyle();
style.font = newBitmapFont();
style.font.setColor(Color.WHITE);
continue= newTextButton("continue",
style);
continue.addListener(newClickListener() {
@Overridepublicvoidclicked(InputEvent event, float x, float y) {
if(manager.update()){ //returns true if the AssetManager is done in case you use an AssetManager
basegameclass.setScreen("menu"); //sets the menu screen
}else{
//not done do nothing or do something else like showing loading not done
}
}
});
To add it to different actors or Buttons it should be simmelar. Just take care that the Stage where the Button is added also is the Inputprocessor
. So make sure you added it like this Gdx.input.setInputProcessor(stage);
In this case i don't think, that you need a whole InputListener
simply take the ClickListener for this small task. The InputListener
gives you a wider range of methods which you dont need i think. It is used to detect touchups
and touchdowns
and slide events and much more which you dont need for a button i think. Maybe for actors that you drag around.
you create this all inside of the constructor of the screen. Never do such things inside of the render method since it would create a new listener every frame. (60 per second!)
Post a Comment for "About Libgdx Addlistener"