The World Object

The world object contains just the necessary information to create the world the camera will scroll around on and display to the user. The actual world is never shown to the user as a visible object:

world.cols=15;
world.rows=15;
world.tileWidth=32;
world.tileHeight=32;
world.height=world.rows*world.tileHeight;
world.width=world.cols*world.tileWidth;
world.map=[];

The cols and rows depict the entire size of the world, and the tileHeight and tileWidth values are used in calculations when determining the camera position and painting the world tiles to the Camera. The height and width are calculated from the first four values, and the map array is filled in with the map data we examined previously.

Get HTML5 Canvas, 2nd Edition 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.