使用示例 with the bucket 我正在尝试而不是使用
if(Gdx.input.isTouched()) {
Vector3 touchPos = new Vector3();
touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
使用 touchUp 和 touchDown。
所以,为了使用它们,我定义:
Vector2 position = new Vector2();
Vector2 velocity = new Vector2();
然后:
public boolean touchDown(int x, int y, int pointer, int button) {
if (x < 800 / 2 && y > 480 / 2) {
//here?? for left movement
}
if (x > 800 / 2 && y > 480 / 2) {
//here?? for right movement
}
return true;
}
一般来说,我知道我有一个位置和一个速度。我必须更新与速度相关的位置,但我不知道该怎么做。
最佳答案
您必须使用增量时间和速度矢量每帧更新对象的位置。
像这样的东西(在渲染中):
position.set(position.x+velocity.x*delta, position.y+velocity.y*delta);
和:
public boolean touchDown(int x, int y, int pointer, int button) {
if (x < 800 / 2 && y > 480 / 2) {
//here?? for left movement
velocity.x = -10;
}
if (x > 800 / 2 && y > 480 / 2) {
//here?? for right movement
velocity.x = 10;
}
return true;
}
public boolean touchUp(int x, int y, int pointer, int button) {
velocity.x = 0;
}
关于android - 如何移动角色 - 尝试应用 touchDown 和 touchUp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17220633/