Chapter 6. Adding Features to Your Game

This chapter is slightly different than the previous several chapters, in that there is no game associated with this chapter. The reason that we're not building a game with the concepts from this chapter is that the concepts covered are either way too complex for a single chapter (there are entire books dedicated to the topic of WebGL, for example) or they're not a particularly good match for use in a game. Also, some of the features mentioned at the end of the chapter are so new that browser support is still minimal (if any) and the stability of the APIs may not be too reliable. For this reason, we'll simply explain each API, provide meaningful examples, and hope this skin-deep introduction is enough to get you excited about the prospects involved with each API.

The first part of the chapter will cover four HTML5 APIs that are very exciting and powerful additions to the browser platform. First and foremost, we'll cover WebGL , which brings the power of OpenGL ES to the browser, allowing for hardware accelerated 3D graphics rendering without any need for a single plugin. Next, we will discuss how we can use web sockets for a thread-like experience, the video API for native video playback and manipulation right from JavaScript, and geolocation, which allows JavaScript to determine the physical location (geographical location) of a user.

Lastly, we'll wrap up the chapter by looking at the absolute latest features in the HTML5 evolution. These features take CSS to the next level, taking it away from being a mere rectangular-based rendering engine. The first new feature that we'll study is CSS shaders, which allows us to specify how each pixel is to be rendered. This is done using GLSL shaders, which, as we'll see during the WebGL discussion, are independent programs that we write and are run on the GPU, controlling at the lowest level possible how something is to be rendered. With custom shaders, we can do so much more than simple, pre-baked CSS transformations.

Other new CSS features, covered in the second half of the chapter, are CSS columns and CSS regions and exclusions. CSS columns make it beautifully easy to dynamically adjust how many columns of text a container displays. For example, if we want a block of text to be displayed in 3 equal width or height columns, we would normally set up three different containers, then float each container to the left. With columns, we can simply store all of the text inside a single container, then use CSS to generate the columns. Finally, CSS regions and exclusions make it possible to render text inside or around complex patterns, instead of the traditional rectangular shape. Surely you have seen magazines doing this, where a block of text wraps around some shape like the outline of a car or some other object. In the past, doing this effect with plain text (as opposed to using images) has very rarely been attempted in HTML because of the extreme complexity required to pull this off. Now it only takes a few lines of CSS code.

Advanced HTML5 APIs

Although the following APIs and features vary greatly in complexity and learning curve steepness, our goal is to provide at least a thorough introduction to each of these topics. In order to gain a deeper understanding of, and working experience with each topic, it is recommended that you supplement the introduction provided here with other sources.

Since parts of the HTML5 specs and features have not yet reached full maturity, some APIs may not be fully supported in all browsers, even the latest modern browsers. Since this chapter will cover the absolute latest features of HTML5 (as at the time of writing), there is a chance some browsers might not be suitable for the examples covered in the chapter. For this reason, it is recommended that you work on the latest version of whatever the most advanced web browser is. Not only that, but you must also make certain that you check whatever experimental feature and/or security flags your browser has available. The following code snippets were written specifically for, and aimed at Google Chrome, since all of the features described are supported by it. We will make a note of any specific configuration settings required for a feature to work properly but these may or may not be needed as new updates are deployed for new web browsers.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.239.226