【发布时间】:2014-11-10 22:45:41
【问题描述】:
我正在尝试使用 LibGDX 和 Java,如果用户的手指正在触摸另一个纹理,我希望根据用户的手指位置使纹理沿 x 轴移动。下面是我的代码,它只在手指向右移动时才有效
game.batch.begin();
game.batch.draw(userCar, carCord.x, carCord.y);
game.batch.draw(touchBound, touchCord.x, touchCord.y);
game.batch.end();
if (Gdx.input.isTouched()) {
Vector3 touchPos = new Vector3();
Rectangle textureBounds=new Rectangle(touchCord.x,touchCord.y,touchCord.width,touchCord.height);
touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
camera.unproject(touchPos);
if(textureBounds.contains(touchPos.x,touchPos.y) {
carCord.x = touchPos.x;
}
}
【问题讨论】:
标签: java libgdx game-physics