触摸没有检测到libgdx按钮
问题描述:
我是新来的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()前一屏幕的方法,只要不叫正常 反正感谢您的帮助
答
其实你不采取行动,Gesture
上一个按钮后解决的问题。这是一个点击或触摸,但不是一个手势。将其更改为ClickListener
和onClick操作,它应该可以工作。 Regards
thanx对于您的建议 但这并没有帮助我 仍触摸未检测 – bindassdost 2013-05-03 10:55:43