Use a Camera

In this new version of Escape, the pit is much bigger than your game window. You make the pit a square 1600 pixels on a side, while the window is 800 pixels square, so you see only one quarter of the game inside the window at any one time. The part of the game space you’ll show will depend on Chip’s location.

images/sidescroller/camera_window.png

It’s as if a camera is following Chip around as he climbs out of the pit. When Chip gets close to an edge of the pit, or to the top or bottom, the camera doesn’t follow him in the same way. Instead, the camera stops so that the whole camera view remains inside the pit.

The Camera Class

Start by making a copy of the Escape folder ...

Get Learn Game Programming with Ruby now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.