So right now I am trying to figure out a way to truly center a sprite, no matter of its size. Right now my current formula is this:
public void addMapObject(PlayerRenderer player) {
player.setMap(this);
int divideWidth = player.getPlayerFrame().getRegionWidth() / (Constants.pixel / 2);
int offsetX = player.getPlayerFrame().getRegionWidth() / divideWidth;
int divideHeight = player.getPlayerFrame().getRegionHeight() / (Constants.pixel / 2);
int offsetY = player.getPlayerFrame().getRegionHeight() / divideHeight;
if (player.getPlayerFrame().getRegionHeight() == Constants.pixel) {
offsetY = 0;
}
if (player.getPlayerFrame().getRegionWidth() == Constants.pixel) {
offsetX = 0;
}
player.setPlayerPosition((width/2) - (player.getPlayerFrame().getRegionWidth()) - offsetX, (height/2) - (player.getPlayerFrame().getRegionHeight()) - offsetY);
mapObjects.addMapObject(player); //Need to make the actor class part of a "abstract life object class" and make PlayerRenderer a sub-class of that class
}
The api I use is libgdx.
But what I am trying to say is that I have a image that is 64x64, another one that is 32x48. I am trying to figure out a way to truly center these sprites on the screen, right now I am having issues dealing with offset’s. Does anyone have any references, or ideas which could be used to help me?