I'm working on a bird's eye view 2D game. I want to zoom in/out based on the entity's speed (similar to GTA 1/2), but I'm struggling with the zooming.

To zoom, I simply scale all the entities by the zoom factor. One problem is that the hit tests are off (still happening with the smaller entities). The other problem is that the object is effectively moving slower (travelling a smaller distance when zoomed in, a larger one when zoomed out).

The only fix I can come up with is to scale all bounding boxes (used in collision detection) as well, and to adjust the speed based on the zoom factor. But that seems wasteful and complex (especially since I'm determining the zoom factor based on the speed).

Is there a better way?

  • 4
    \$\begingroup\$ Don't scale the entities, only scale your rendering. \$\endgroup\$
    – msell
    Commented Jun 11, 2013 at 7:14
  • \$\begingroup\$ @msell Well, I'm not scaling them, I'm rendering them scaled (using rotozoomSurface from SDL GFX). SDL doesn't appear to have something like glScale. \$\endgroup\$
    – futlib
    Commented Jun 11, 2013 at 7:21

1 Answer 1


Scaling just the entities won't work. One of the obvious reasons are that you won't scale the distances between them. What you need is a camera concept.

I suppose you are making the game from the scratch, no engine. You will need to implement a position transformation that will happen for every entity just before it gets rendered. E.g. if your rectangular entity is 100x100 pixels big, center of you screen is at [0, 0] and the center of the entity is at [-50,-50] (top right corner of the entity is in the center of the screen) then before rendering with zoom factor 2, scale it to 200x200, and position it to [-100, -100]. Same with every other position and vector in the game.

Note that this is a very naive approach. I believe modern 2D engines use 3D ortogonal projection. The 3D library (OpenGL, Direct X) and the hardware then take care of the scaling.

  • \$\begingroup\$ Unfortunately, I can't use OpenGL here. Seems like I really do have to scale the whole world then... \$\endgroup\$
    – futlib
    Commented Jun 11, 2013 at 9:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .