# Slick2D : translate -> scale -> translate doesn't return to the old position

I am trying to implement zoom using Slick2D library.

As I understand, to zoom something on non (0,0) coordinates, we need:

• translate so the target point is in (0,0)
• apply scale factor
• translate the target point back from (0,0)

Code example :

 aGraphics.translate(-width/2, -height/2);
aGraphics.scale(2,2);
aGraphics.translate(width/2, height/2);


The issue is, as far I understand, that the scale factor is applied to the translation too. To compensate this, I have use the next code :

 aGraphics.translate(-width/2, -height/2);
aGraphics.scale(2,2);
aGraphics.translate(width/4, height/4);


Is this expected behaviour for graphics ? Can I workaround the above effect using push/pop matrix ?

• After you scale your object by scale, your coordinates will be scale times bigger. So try multiplying the offset by the scale factor, after the scale have been applied. aGraphics.translate(offsetX*scaleX, offsetY*scaleY); – Gustavo Maciel Jul 9 '13 at 16:10
• Yep. You've adjusted the second translation backwards; you need to use (width, height) in the second one instead of (width/4, height/4). – Nathan Reed Jul 9 '13 at 17:04
• @NathanReed, could you please detail your answer? Yes - it's expected, or Yes - there is a workaround ? – StKiller Jul 9 '13 at 18:39
• @AndreiPodoprîgora I was agreeing with Gustavo's comment. – Nathan Reed Jul 9 '13 at 20:45