텍스트 버튼이 정상적으로 그려 지지만 (오류 또는 경고 없음) 마우스 클릭에는 응답하지 않습니다. 상황은 데스크톱 및 Android 빌드에서 동일합니다. 나는 그 결과에 대한 모든 주제를 읽고 따라 갔다. 내가 도대체 뭘 잘못하고있는 겁니까?LibGDX TextButton이 마우스 클릭에 응답하지 않습니다.
어쩌면 무대 개체에서 뭔가를 설정해야합니까?
public class MenuScreen implements Screen {
private OrthographicCamera camera;
private BitmapFont font;
private TextureAtlas menuGraphics;
Stage stage;
TextButton button;
TextButtonStyle buttonStyle;
Skin skin;
public MenuScreen(Game game)
{
//create satage object
stage = new Stage();
//create font object
font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"),false);
font.setColor(Color.RED);
//load buttons texture atlas and create Skin object
menuGraphics = new TextureAtlas(Gdx.files.internal("buttons/buttons.pack"));
skin = new Skin();
skin.addRegions(menuGraphics);
// Store the default libgdx font under the name "defaultFont".
skin.add("defaultFont",font);
//Set button style
buttonStyle = new TextButtonStyle();
buttonStyle.up = skin.newDrawable("yellow");
buttonStyle.down = skin.newDrawable("orange");
buttonStyle.checked = skin.newDrawable("orange");
buttonStyle.over = skin.newDrawable("orange");
buttonStyle.font = skin.getFont("defaultFont");
skin.add("default", buttonStyle);
//assign button style
button=new TextButton("PLAY",buttonStyle);
button.setPosition(200, 200);
button.setSize(200,200);
//add button to stage
stage.addActor(button);
//add click listener to the button
button.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
button.setText("Starting new game");
Gdx.app.log("MenuScreen", "clicked button");
}
});
Gdx.app.log("MenuScreen", "create");
}
@Override
public void resize(int width, int height)
{
float aspectRatio = (float) width/(float) height;
camera = new OrthographicCamera(640, 360);
camera.translate(320,180);
camera.update();
stage.setViewport(new FillViewport(640, 360, camera));
stage.getViewport().setCamera(camera);
Gdx.app.log("MenuScreen", "Resizing screen to: " + width + " x " + height);
}
@Override
public void show() {
Gdx.input.setInputProcessor(stage);
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
resize((int)w,(int)h);
Gdx.app.log("MenuScreen", "Show screen code");
}
@Override
public void render(float delta)
{
Gdx.gl.glClearColor(0f, 1f, 0f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(delta);
// draw the actors
stage.draw();
}
@Override
public void dispose()
{
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
}
이것이 http://stackoverflow.com/questions/11373390/button-clicklistener-is-not-working-in-libgdx-game – nikoliazekter