我的游戏控制有问题。
这是我的main_class:
public class main_class extends ApplicationAdapter implements GestureListener{
SpriteBatch batch;
Texture img;
int screen_height;
int screen_width;
@Override
public void create () {
batch = new SpriteBatch();
img = new Texture("player.png");
screen_height = Gdx.graphics.getHeight();
screen_width = Gdx.graphics.getWidth();
GestureDetector gestureDetector = new GestureDetector(this);
Gdx.input.setInputProcessor(gestureDetectore); // Here is error (gestureDetector cannot be resolved to a variable)
}
@Override
public void render () {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(img, screen_width / 3, screen_height / 2);
batch.end();
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
}
@Override
public boolean touchDown(float x, float y, int pointer, int button) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean tap(float x, float y, int count, int button) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean longPress(float x, float y) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean fling(float velocityX, float velocityY, int button) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean pan(float x, float y, float deltaX, float deltaY) {
return false;
}
@Override
public boolean panStop(float x, float y, int pointer, int button) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean zoom(float initialDistance, float distance) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean pinch(Vector2 initialPointer1, Vector2 initialPointer2,
Vector2 pointer1, Vector2 pointer2) {
// TODO Auto-generated method stub
return false;
}
}
我想通过平移位置(y)改变玩家的位置(y)。 我想通过向上和向下滑动显示来控制播放器。 谢谢你的回复。
答案 0 :(得分:0)
您实际上没有初始化您的GestureDetector。让我们初始化它,然后最终设置输入处理器:
Gdx.input.setInputProcessor();
你应该实现GestureListener
public class main_class extends ApplicationAdapter implements GestureListener {
所以在create方法中做这些事情。
public void create () {
..
GestureDetector gestureDetector = new GestureDetector(this);
Gdx.input.setInputProcessor(gestureDetector);
}