本文介绍了按钮ClickLIstener不是工作在LibGdx游戏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发使用libgdx安卓游戏;有在菜单画面4按钮,但点击这些按钮的监听器不能正常工作。
I am developing android game using libgdx; there are 4 button in menu screen, but click listener of these button is not working.
// 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.setClickListener( new ClickListener() {
@Override
public void click(Actor actor,float x,float y )
{
System.out.println("hiii");
Assets.load();
//game.getSoundManager().play( TyrianSound.CLICK );
game.setScreen( new GameScreen(game) );
}
} );
layout.register( "startGameButton", startGameButton );
如何在libgdx处理按钮clicklistener?没有图像按钮,但其布局按钮。
How to handle clicklistener of button in libgdx? Not Image button, but its layout button.
推荐答案
您必须将按钮添加到舞台,并呼吁
You have to add the button to the stage and call
Gdx.input.setInputProcessor(stage);
这篇关于按钮ClickLIstener不是工作在LibGdx游戏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!