LibGdx 2 half screen “buttons”

谁说我不能喝 提交于 2020-01-11 11:38:07

问题


(Android) So I'm new to LibGdx and I'm trying to code this chrome dino mini game.. I want to make action 1 when the user touch the left hand side of the screen and make action 2 when he touch the right hand side of the screen, how can I do it?


回答1:


You can detect the side being touched by using the following code somewhere inside your game loop:

if (Gdx.input.isTouched()) {
    if (Gdx.input.getX() > Gdx.graphics.getWidth() / 2){
        //touched right
    } else {
        //touchde left
    }
}


来源:https://stackoverflow.com/questions/46549859/libgdx-2-half-screen-buttons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!