我正在尝试从屏幕中心绘制纹理到触摸坐标(时钟指针)。为了说明这一点,我创建ShapeRenderer
了一条从中心到接触点的线。代码下方
if (Gdx.input.isTouched()) {
camera.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
debugRenderer.begin(ShapeType.Line);
debugRenderer.setColor(Color.ORANGE);
debugRenderer.line(centerObject.x, centerObject.y, touchPoint.x, touchPoint.y);
debugRenderer.end()
}
这工作正常。现在我需要用实际图像替换线(我需要根据触摸位置进行缩放)。我尝试从中心点绘制纹理。我想使用
public void draw (TextureRegion region, float x, float y, float originX, float originY, float width, float height,
float scaleX, float scaleY, float rotation)
SpriteBatch
帮助我绘制纹理。但它不起作用。代码下方
private TextureRegion handRegion;
private Texture handTexture;
handTexture = new Texture(
Gdx.files.internal("hand.png"));
handRegion = new TextureRegion(handTexture);
//origin_X,origin_Y are the center of the screen
if (Gdx.input.isTouched()) {
camera.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
game.batch.begin();
game.batch.draw(handRegion, touchPoint.x, touchPoint.y, origin_X, origin_Y,10,100,1,1,0);
game.batch.end();
}
我非常感谢任何帮助解决这个问题。