这是我的代码: 包com.mygdx.game;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class MyGdxGame extends ApplicationAdapter {
SpriteBatch batch;
Texture img;
@Override
public void create () {
Gdx.input.setCatchBackKey(true);
batch = new SpriteBatch();
img = new Texture("badlogic.jpg");
}
@Override
public void render () {
if (Gdx.input.isKeyJustPressed(Input.Keys.BACK)) {
Gdx.app.log("Debug", "Back pressed!");
Gdx.app.exit();
}
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(img, 0, 0);
batch.end();
}
}
我不知道为什么代码没有按预期工作,当我用“isKeyPressed”替换“isKeyJustPressed”时它完美无缺。 或者用Keys.ESCAPE(在桌面模块上运行)替换Keys.Back。
有什么想法吗?感谢
答案 0 :(得分:0)
Keys.BACK可能不是你想要的。尝试Keys.BACKSPACE