Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.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.translate(width/4, height/4);

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

share|improve this question
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
up vote 0 down vote accepted

Seems that slick 2d doesn't consider the center coordinates when scaling. It just multiplies any coordinates using current scale.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.