libgdx 演员输入无效

libgdx actor input not working

我在 libgdx 中的演员正常绘制 inputlistener 如何不工作,我已经检查我启动了 Gdx.input.setInputProcessor 我很确定我的边界设置正确所以请帮忙我有这个问题。

代码:

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);
}

主要class:

    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();

}

尝试:

setBounds(playButton.getX(), playButton.getY(), playButton.getWidth(), playButton.getHeight())