[Libgdx] Strange issue when scaling a sprite

I’m trying to stretch a sprite to screen bounds uniformly. First I set the origin of the sprite to the centre of the screen. Since it’s an Android device, I have several pages to scroll through to reach the end. In my experience, width*2 covers the extra distance.

mSprite.setOrigin(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()/2);
//these return 1080 and 960 on my device

Next I set the sprite’s X and Y relative to the origin:

mSprite.setPosition(mSprite.getOriginX()-mSprite.getWidth()/2, mSprite.getOriginY()-mSprite.getHeight()/2);
//sprite width and height are 1440 and 1280

Now draw it with

mSprite.draw(batch)

To a naked eye, it doesn’t look off. Having measured the distance, there is no difference.

Now I apply a scale:

mSprite.setScale(1.2f, 1.2f);

Result:

As you can see, after scaling, the sprite no longer appears to be in the centre.

Why? What am I doing wrong? If this is how it’s supposed to work, can anyone please recommend a viable workaround to uniformly scale a sprite?

Thanks

use:

mSprite.setOriginCenter();

do this after setting the position, and remove your setOrigin line of code.

Thanks, I figured it out. Origin should be set to centre of the sprite. I shouldn’t have set my position relative to the origin. It should be set relative to the surface instead.