Last week we started work on the game’s camera by creating a component that continuously centres the View on the player’s character. This week we’ll work on the ability to zoom in and out of the scene. What may surprise you is that we are not extending the functionality of the camera, we will, in fact, be implementing zoom in the Debug class. We’re doing it this way because I don’t think we’ll want the player to be able to use the zoom in the final game and you’ll remember from when we started the Debug class that it will include anything that we do not want in the final game but will be used for testing purposes. Zoom fits this criteria nicely.
The function checks if a bracket key has been pressed and then either zooms in or out. The zoom uses the same process as the movement code from the last tutorial, where we first retrieve the windows View, modify it in some way (in this case by zooming), and then setting the windows View to our newly edited View.
Zoom works relative to the current Views zoom so we do not need to increase/decrease the amount we are zooming each time, we can instead use a flat scale of 1.1 or 0.9. It also does not magically work in any 3D way, the camera is not moving closer to our sprites rather it is simulating the zoom by enlarging or shrinking the zone displayed onscreen.
That’s it for this week! Next week we are going to extend our animation system so that we can animate entities in four directions (rather than just the left/right that we have now). To test the extension to our animation system we’ll change to a top-down perspective used by many 2D role playing and adventure games.