libgdx setOrigin and setPosition not working as expected?

Posted by shino on Game Development See other posts from Game Development or by shino
Published on 2012-07-04T15:13:16Z Indexed on 2012/07/04 15:24 UTC
Read the original article Hit count: 832

Filed under:
|

I create a camera:

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

Create a sprite:

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);

Set the origin, size, and position:

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

Then render it:

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

But when I render it, the bottom left of my ball sprite is at (0, 0), not the center of it, as I would expect it to be because I set the origin to the center of the sprite. What am I missing?

© Game Development or respective owner

Related posts about android

Related posts about libgdx