Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
4  
Don't scale the entities, only scale your rendering. –  msell Jun 11 '13 at 7:14
    
@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. –  futlib Jun 11 '13 at 7:21

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
Unfortunately, I can't use OpenGL here. Seems like I really do have to scale the whole world then... –  futlib Jun 11 '13 at 9:25

Your Answer

 
discard

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.