-1
我的演員在libgdx通常繪製inputlistener如何不工作,我已檢查,我發起了Gdx.input.setInputProcessor,我很確定我的界限設置正確,所以請幫助我與這個問題。libgdx演員輸入不起作用
代碼:
Sprite playButton = new Sprite(new Texture(Gdx.files.internal("badlogic.jpg")));
public playBtn(){
setBounds(playButton.getX(),playButton.getY(),getWidth(),getHeight());
setTouchable(Touchable.enabled);
addListener(new InputListener(){
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
Gdx.app.log("Example", "touch started at (" + x + ", " + y + ")");
return false;
}
@Override
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
Gdx.app.log("Example", "touch done at (" + x + ", " + y + ")");
}
});
}
@Override
public void draw(Batch batch, float parentAlpha) {
playButton.draw(batch);
}
@Override
public void act(float delta) {
super.act(delta);
}
主要類:
public MenuState(GameStateManager gsm){
super(gsm);
ScreenViewport screenViewport = new ScreenViewport();
menuStage = new Stage(screenViewport);
playBtn playButton= new playBtn();
menuStage.addActor(playButton);
Gdx.input.setInputProcessor(menuStage);
background = new Sprite(new Texture("MenuBG.png"));
project = new Project();
background.setSize(project.WIDTH,project.HEIGHT);
}
@Override
protected void handleInput() {
}
@Override
public void update(float dt) {
handleInput();
}
@Override
public void render(SpriteBatch sb) {
sb.begin();
background.draw(sb);
sb.end();
menuStage.act(Gdx.graphics.getDeltaTime());
menuStage.draw();
}
「的inputlistener不工作」 不幫助那麼多。你可能想解釋它不工作的方式。它做錯了什麼嗎?它根本沒有被召喚?此外,您可能需要稍微清理一下已發佈的代碼,以便於閱讀。 – Thomas
@Thomas是的,我確定我會再次編輯它,並且inputlistener不會被調用 – icedbluw