簡體   English   中英

TextButton isPressed()不起作用

[英]TextButton isPressed() not working

我在scene2d中遇到問題。 我已經以編程方式創建了一個TextButton(沒有json文件),由於某種原因,當我按下它時isPressed()不會返回true。 不僅如此,我還設置了TextButtonStyle的downFontColor,但它也不執行任何操作。 這是我第一次使用scene2d,所以我還是很新。 我正在android上進行測試。

我使用了一個自定義類,該類擴展了TextButton,它與問題無關,它只是一個空類。 不要碰我已經在textbutton上測試過了。 繼承人的課程:

我在其中創建Stage的MainMenu:

public MainMenu(Main main) {

    this.main = main;

    font_neutral = Tools.generateFont(Gdx.files.internal("Fonts/Android.ttf"), Color.WHITE, 150);

    initViewport();

    //Scene2D
    GlyphLayout glyphLayout = new GlyphLayout(); //Used for getting width/height of textButton. Set text, then get width

    TextButton.TextButtonStyle style = new TextButton.TextButtonStyle();
    style.font = font_neutral;
    style.fontColor = new Color(1, 1, 1, 1);
    style.downFontColor = new Color(40, 130, 100, 1);
    style.checkedFontColor = Color.BLUE;

    CustomTextButton button_play = new CustomTextButton("Play", style);
    glyphLayout.setText(style.font, "Play");
    float x = camera.viewportWidth / 3 - glyphLayout.width / 2;
    float y = camera.viewportHeight / 2 - glyphLayout.height / 2;
    button_play.setPosition(x, y);
    button_play.setTouchable(Touchable.enabled);

    stage = new Stage(viewport);
    stage.addActor(button_play);
}

@Override
public void show() {

}

public void update(float delta) {

    stage.act(delta);


}

@Override
public void render(float delta) {
    update(delta);

    Gdx.gl.glClearColor(1, 1, 1, 0);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    Gdx.gl.glEnable(GL20.GL_BLEND);

    stage.draw();

}

再次感謝!

Stage是一個InputProcessor ,您需要告訴LibGDX監聽Stage 在初始化Stage之后,放入Gdx.input.setInputProcessor(stage)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM