Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
5  
You cross posted this on SO, then posted the answer you got there as your own here. That's not the way we do things here. –  Byte56 Jul 6 '12 at 4:04
add comment

1 Answer 1

up vote 1 down vote accepted

setOrigin does not affect translation, only rotation and scaling.

share|improve this answer
    
As you said, setOrigin() doesn't affect translation, in order to center the sprite at 0,0 you have to setPosition(-w/2, -h/2). Not sure if it is normal to answer your own question in stackoverflow, maybe you have to add a comment instead. –  arielsan Aug 24 '12 at 14:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.