I'm having a bit of trouble programming the camera view for a 2D platformer. Essentially, I want to scroll the camera in a tile-based level when the player moves in a particular direction. I'm storing the entire level in an array like so:
// Just an example
var level = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 0, 1, 1, 1, 1, 1
];
// 0 = empty, 1 = tile
I know how to scroll the camera by altering its (X,Y) coordinates within the overworld width and height, but how do I figure out which tiles to draw on the canvas (only the tiles within the camera's view, including partial tiles)?