0
votes

I have some problems with font drawing in the center of the sprite. The sprite is moving along the screen. I set my orthographic camera to:

w = Gdx.graphics.getWidth();
h = Gdx.graphics.getHeight();
camera = new OrthographicCamera(1, h/w);

and:

Sprite spr = new Sprite(starTx);
spr.setSize(0.3f, 0.3f);
spr.setOrigin(0.15f, 0.15f);
spr.setPosition(0.2f, 0.25f*(i+1));

Inside render I have the code:

batch.setProjectionMatrix(camera.combined);
batch.begin();
spr.draw(batch);
font.setScale(1, (w/h)*3);
font.draw(batchFont, mDate, valueX, valueY);
batch.end();

I must draw the font in the center of the sprite. Could anyone tell me how to calculate valueX and ValueY?

1
I found by myself the answer: x = (spr.getX()+0.5f)*(screen.width()) - Duna

1 Answers

0
votes

Not exactly what you posted, the screen width is 1, so multiplying for it is useless :p More general approach:

valueX = spr.getX()+spr.getWidth()/2F;
valueY = spr.getY()+spr.getHeight()/2F;