我在比赛中的控制能力有问题。
这是我的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)。我想通过上下滑动屏幕来控制玩家。谢谢你的回应。
发布于 2014-09-09 21:25:47
您实际上没有初始化您的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);
}https://stackoverflow.com/questions/25750877
复制相似问题