LibGDX touchDown仅适用于Android,而不适用于桌面

时间:2017-02-25 13:24:50

标签: java android libgdx

在Android Studio开发过程中,我遇到了触摸和点击演员的问题。

我正在使用本教程的帮助: http://www.gamefromscratch.com/post/2013/11/27/LibGDX-Tutorial-9-Scene2D-Part-1.aspx

代码片段是这样的:

public class MyActor extends Actor {
    Texture texture = new Texture(Gdx.files.internal("data/jet.png"));
    float actorX = 0, actorY = 0;
    public boolean started = false;

    public MyActor(){
        setBounds(actorX,actorY,texture.getWidth(),texture.getHeight());
        addListener(new InputListener(){
            public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
                ((MyActor)event.getTarget()).started = true;
                return true;
            }
        });
    }


    @Override
    public void draw(Batch batch, float alpha){
        batch.draw(texture,actorX,actorY);
    }

    @Override
    public void act(float delta){
        if(started){
            actorX+=5;
        }
    }
}

现在我在Android和PC上进行调试。有了这个片段,如果我在PC或手机上点击演员,那么演员移动得很好。

但是,我已对此代码进行了一些修改以满足我的需求,这就是现在的样子:

public class Play_Btn extends Actor {

    Texture texture = new Texture(Gdx.files.internal("menubuttons/play_btn.png"));

    float actorX = game.screen_width/2 - tiledimensions*4/2;
    float actorY = tiledimensions*howmanytobottom-tiledimensions*5;

    public boolean started = false;

    public Play_Btn(){
        setBounds(actorX,actorY,tiledimensions*4,tiledimensions*4);
        addListener(new InputListener(){
            public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
                ((Play_Btn)event.getTarget()).started = true;
                Gdx.app.debug("The button has been pressed", "");
                return true;
            }

        });
    }


    @Override
    public void draw(Batch batch, float alpha){

        batch.draw(texture, actorX,actorY, tiledimensions*4, tiledimensions*4);
    }

    @Override
    public void act(float delta){


        if(started){
            actorX +=5 ;
        }
    }
}

现在的情况是,如果我在Android上调试它,它的工作方式相同,完全没问题。

但是,如果我在PC上点击这个演员,没有任何反应,我很好奇为什么会这样。

有没有人遇到过这个问题或类似问题?

提前致谢!

0 个答案:

没有答案