我有一个扩展 Actor 的类 Bubble。
public Bubble(MyGdxGame game,Texture texture){
this.game=game;
setPosition(0,0);
setSize(32,32);
gameObject=new GameObject("","bubble");
direction=new MovementDirection();
sprite=new Sprite(texture);
setTouchable(Touchable.enabled);
setWidth(sprite.getWidth());
setHeight(sprite.getHeight());
setBounds(0,0,sprite.getWidth(),sprite.getHeight());
addListener(new InputListener() {
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
Gdx.app.log("BUBBLE", "touchdown");
return true; // must return true for touchUp event to occur
}
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
Gdx.app.log("BUBBLE", "touchup");
}
});
}
这是在实现 Screen 的类中
public void show() {
// TODO Auto-generated method stub
super.show();
//2 bubbles test
gameStage=new Stage(MyGdxGame.WIDTH,MyGdxGame.HEIGHT,true);
Gdx.input.setInputProcessor(gameStage);
for (int i=0; i<10; i++){
Bubble b=new Bubble(game,Assets.bubbleTexture);
b.randomize();
gameStage.addActor(b);
}
//if (bubbleList==null)
// createBubbles();
}
通过添加侦听器@气泡级别,我是否会以错误的方式解决这个问题?(似乎为我生成的每个气泡创建一个 InputListener 有点疯狂)。
根据:http : //libgdx.l33tlabs.org/docs/api/com/badlogic/gdx/scenes/scene2d/Actor.html Actor 有一个 touchUp() 和 touchDown 事件 - 但是当我尝试覆盖它们时会抱怨(让我相信它们不存在)。覆盖这些我觉得会是一个更好的方法