libgdx setOrigin和setPosition没有按预期工作?

时间:2012-07-04 03:53:03

标签: android libgdx

我创建了一个摄像头:

camera = new OrthographicCamera(5.0f, 5.0f * h/w);

创建精灵:

ballTexture = new Texture(Gdx.files.internal("data/ball.png"));
ballTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
TextureRegion region = new TextureRegion(ballTexture, 0, 0, ballTexture.getWidth(), ballTexture.getHeight());
ball = new Sprite(region);

设置原点,大小和位置:

ball.setOrigin(ball.getWidth()/2,ball.getHeight()/2);
ball.setSize(0.5f, 0.5f * ball.getHeight()/ball.getWidth());
ball.setPosition(0.0f, 0.0f);

然后渲染它:

batch.setProjectionMatrix(camera.combined);
batch.begin();
ball.draw(batch);
batch.end();

但是当我渲染它时,我的球精灵的左下角是(0,0),而不是它的中心,正如我所期望的那样,因为我将原点设置为精灵的中心。我错过了什么?

1 个答案:

答案 0 :(得分:7)

原点与旋转和缩放有关,如方法JavaDocs中所述。