0
我是新來的libgdx和學習libgdx scene2d。觸摸沒有檢測到libgdx按鈕
在菜單屏幕構造我創造了一個舞臺與設備的分辨率 並添加階段輸入處理器:
stage = new Stage(800, 480, false);
stage.getCamera().position.set(400, 240, 0);
Gdx.input.setInputProcessor(stage);
現在,我創建了一個按鈕,並把它添加到舞臺:
PButton start = new PButton(Assets.btn, Assets.btn_p, Assets.font50,
"START");
start.setPosition(600, 400);
start.addListener(new ActorGestureListener() {
@Override
public void touchUp(InputEvent event, float x, float y,
int pointer, int button) {
super.touchUp(event, x, y, pointer, button);
getGame().setScreen(new GameScreen1(getGame()));
System.out.println("set game");
}
});
stage.addActor(start);
其中PButton
將Button
類擴展爲:
public class PButton extends Button {
private BitmapFont font;
private String text;
private float sizex;
private float sizey;
private float posx;
private float posy;
public PButton(TextureRegion up, TextureRegion down, BitmapFont font,
String text) {
super(new TextureRegionDrawable(up), new TextureRegionDrawable(down));
this.font = font;
this.text = text;
this.sizex = up.getRegionWidth();
this.sizey = down.getRegionHeight();
setSize(sizex, sizey);
font.setScale(Initiate.getM_ratio());
}
@Override
public void draw(SpriteBatch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
font.draw(batch, text, posx + sizex/2 - font.getBounds(text).width
/2, posy + sizey/2 + font.getBounds(text).height/2);
}
@Override
public void setPosition(float x, float y) {
this.posx = x;
this.posy = y;
super.setPosition(posx, posy);
}
}
但是當我點擊按鈕時,它沒有得到輸入。
UPDATE:深調試我發現我的stage.dispose()前一屏幕的方法,只要不叫正常 反正感謝您的幫助
thanx對於您的建議 但這並沒有幫助我 仍觸摸未檢測 – bindassdost 2013-05-03 10:55:43