Handling Window Re-sizing in the Browser
It's time to do a little house-keeping maintenance on our game template. I know, that doesn't sound as exciting as player movement and dynamic lighting, but it is just as important. What we are looking to do in this post is learn how to handle when the user suddenly changes the browser window size. This happens quite frequently, so we need to have code in place to quickly re-size our game graphics too. Otherwise, our viewport will get stretched out of proportion or it might get cut off so the user cannot see the whole picture. Let's take a look at how to keep the browser view centered and in proportion. Every webpage on the internet has a global 'window' object that contains the entire webpage. The 'window' is like the trunk of a tree and our game is somewhere out on the branches. Everything on our webpage is connected back to the 'window' object. The window object is created for us when we open a browser, and it comes ...