samedi 28 février 2015

Java Graphics2D scale doubling



I'm having trouble scaling objects with Graphics2D in Java. In my paintComponent I create two graphics2D objects for easier management. I then try to scale them. The problem is that the output is scaled x4 (the scale commands affect each other). Otherwise everything renders as it should.


How is this best solved.


The code in question:



@Override
public void paintComponent(Graphics g) {
playerGraphics = (Graphics2D) g;
backgroundGraphics = (Graphics2D) g;

playerGraphics.scale(2.0, 2.0);
backgroundGraphics.scale(2.0, 2.0);

backgroundGraphics.drawImage(background.getBackground(), 0, 0, null);

for(int i = 0; i < noPlayers; i++) {
playerGraphics.drawImage(players.get(i).getCurrentSprite(), players.get(i).getXPos(), players.get(i).getYPos(), null);
}
}



Aucun commentaire:

Enregistrer un commentaire