[英]Button ClickListener is not working in LibGDX game
I am developing an Android game using LibGDX. 我正在使用LibGDX开发Android游戏。 There are 4 buttons in a menu screen, but the
ClickListener
of these buttons is not working. 菜单屏幕中有4个按钮,但这些按钮的
ClickListener
不起作用。
// retrieve the custom skin for our 2D widgets
Skin skin = super.getSkin();
// create the table actor and add it to the stage
table = new Table( skin );
table.width = stage.width();
table.height = stage.height();
stage.addActor( table );
// retrieve the table's layout
TableLayout layout = table.getTableLayout();
// register the button "start game"
TextButton startGameButton = new TextButton( "Start game", skin );
startGameButton.addListener( new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
System.out.println("hiii");
Assets.load();
// game.getSoundManager().play( TyrianSound.CLICK );
game.setScreen( new GameScreen(game) );
}
} );
layout.register( "startGameButton", startGameButton );
How to activate the ClickListener
of a button in LibGDX? 如何在
ClickListener
中激活按钮的ClickListener?
您必须将按钮添加到舞台并调用
Gdx.input.setInputProcessor(stage);
Instead of "click method" now it's "clicked method" (I think!), just in case someone faces the same problem I was facing when found this question: 而不是“点击方法”现在它是“点击方法”(我想!),以防万一有人面临同样的问题我遇到了这个问题:
startGameButton.addListener( new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
game.setScreen( new GameScreen(game) );
};
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.