2
這是使我感到困惑的代碼。我可能會在這裏失去一些東西,但無法弄清楚。LIBGDX:當類擴展scene2d.Stage時,不會調用hit()方法
public class TStage extends Stage {
public TStage(float width, float height, boolean stretch) {
super(width, height, stretch);
}
@Override
public Actor hit(float x, float y) {
Gdx.app.debug("HUNT", "in hit of TStage");
return super.hit(x, y);
}
}
public class TActor extends Actor {
@Override
public void draw(SpriteBatch batch, float parentAlpha) {
// draw something here
}
@Override
public Actor hit(float x, float y) {
Gdx.app.debug("HUNT", "in hit of TActor");
return null;
}
}
/* Code to set stage*/
TStage stage = new TStage(Hunt.GAME_WIDTH, Hunt.GAME_HEIGHT, false);
Gdx.input.setInputProcessor(stage);
TActor actor1 = new TActor();
stage.addActor(tactor);
當我觸摸屏幕
輸出:
in hit of TActor
什麼我期待:
in hit of TStage
in hit of TActor
[編輯]
我添加以下代碼TStage
@Override
public Actor touchDown(int x, int y, int pointer, int button) {
Gdx.app.debug("HUNT", "in touchDown of TStage");
return super.touchDown(x, y, pointer, button);
}
現在輸出的是:
in touchDown of TStage
in hit of TActor
是的,你是對的。我在輸出中添加了您的建議。似乎是這樣的路要走。 – Pradeep