【发布时间】:2015-12-05 18:26:43
【问题描述】:
我正在学习 libGDX,只是为了好玩,而且很早就碰壁了。我的演员似乎没有收到触摸/鼠标输入。我已经广泛搜索并检查了所有常见错误(设置输入过程,设置边界,设置可触摸),但仍然没有运气。谁能帮帮我。
舞台
/* GameStage.java */
public class GameStage extends Stage{
private Game gameInstance;
public GameStage(Game gameInstance) {
super(new ScreenViewport());
Gdx.input.setInputProcessor(this);
Tile tile = new Tile(2);
addActor(tile);
}
}
演员
/* Tile.java */
public class Tile extends Actor{
public enum Side{
FRONT,
BACK
}
private int value;
private Texture backTexture;
private Texture frontTexture;
private Side currentSide;
public Tile(int value) {
this.value = value;
backTexture = new Texture("TileBack.png");
frontTexture = new Texture("Tile " + String.valueOf(value)+".png");
currentSide = Side.BACK;
setPosition(0, 0);
setSize(128, 128);
setBounds(getX(), getY(), getWidth(), getHeight());
setTouchable(Touchable.enabled);
addListener(new InputListener(){
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("Touch");
super.touchUp(event, x, y, pointer, button);
}
});
}
@Override
public void draw(Batch batch, float parentAlpha) {
Color color = getColor();
batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
if(currentSide == Side.BACK){
batch.draw(backTexture, getX(), getY(), getWidth(), getHeight());
}
else{
batch.draw(frontTexture, getX(), getY(), getWidth(), getHeight());
}
}
public int getValue() {
return value;
}
}
我错过了什么?我也尝试在舞台上实现 touchUp 并返回 false 和 true 但没有运气。
提前致谢!
【问题讨论】: