这是我的代码:
public WelcomeScreen(final WallGame game) {
this.game = game;
// Setting up camera and viewport.
camera = new OrthographicCamera();
viewport = new StretchViewport(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera);
viewport.apply();
stage = new Stage(viewport);
camera.position.set(camera.viewportWidth / 2, camera.viewportHeight / 2, 0);
Gdx.input.setInputProcessor(stage);
skin = new Skin(Gdx.files.internal("uiskin.json"));
skin.getFont("default-font").getData().setScale(0.1f, 0.1f);
backgroundTxtr = new Texture(Gdx.files.internal("background/background.png"));
background = new Image(backgroundTxtr);
background.setBounds(0, 0, GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT);
final TextButton button = new TextButton("start", skin, "red-button");
button.setBounds(10, 10, 50, 50);
button.setTouchable(Touchable.enabled);
button.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
Gdx.app.log("AKS", "CLICKED");
}
});
final Dialog dialog = new Dialog("Click Message", skin);
dialog.setBounds(50, 50, 40, 40);
stage.addActor(background);
stage.addActor(button);
stage.addActor(dialog);
}
我似乎无法使按钮工作,我点击了按钮时显示的图像(TextButton
的“向下”属性),但它没有改变。我做错了什么?
答案 0 :(得分:-1)
我明白了。我没有创建一个Table
对象来添加按钮。在我这样做之后它起作用了。