28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 5 ■ An Introduction to Game Design: Concepts, Multimedia, and Using Scene Builder<br />

The optimization concept regarding frames in an Animation object or digital video asset is very similar to the<br />

optimization concept regarding pixels in an image (the resolution of a digital image): the fewer used, the better! This<br />

is because the number of frames in an animation or video multiplies both the system memory used and the filesize<br />

data footprint with each frame. In digital video, not only does each frame’s (image) resolution, but also the frame rate<br />

(specified in the Compression Settings dialog) impact file size. Earlier in this chapter, you learned that if you multiply<br />

the number of pixels in the image by its number of color channels, you will get the raw data footprint for the image.<br />

With animation and digital video, you will now multiply that number again by the number of frames that need to be<br />

used to create the illusion of motion.<br />

Therefore, if you have an animated VGA (RGB) background plate for your game (remember that each frame is<br />

900KB) that uses five frames to create the illusion of motion, you are using 900KB × 5, or 4,500KB (4.5MB), of system<br />

memory to hold that animation. Of course, this is too much memory to use for a background, which is why you will<br />

be using static backgrounds with sprite overlays to achieve this exact same end result in less than a megabyte. The<br />

calculation for digital video is a bit different, as it has hundreds or thousands of frames. For digital video you would<br />

multiply your raw image data size by the number of frames per second (frame rate) at which the digital video is set to<br />

play back (this frame rate value is specified during the compression process), and then multiply that result by the total<br />

number of seconds of content duration contained in your video file.<br />

To continue with the VGA example, you know that a 24-bit VGA image is 900KB. This makes the calculation<br />

to take this to the next level easy. Digital video traditionally runs at 30FPS, so 1 second of standard definition raw<br />

(uncompressed) digital video would be 30 image frames, each of which is 900KB, yielding a total data footprint of<br />

27,000KB! You can see why having video compression file formats such as MPEG-4 H.264 AVC, which can compress<br />

the massive raw data footprint that digital video can create, is extremely important. The <strong>Java</strong>FX media package uses<br />

one of the most impressive video compression codecs (“codec” stands for code-decode) which is also supported<br />

in HTML5 and Android, the aforementioned MPEG-4 H.264 AVC (advanced video codec). This is quite convenient<br />

for developer asset optimization, as one single digital video asset can be used across <strong>Java</strong>FX, HTML5, and Android<br />

applications. Just in case you want to use digital video in the background of your game (which I do not recommend), I<br />

am going to cover the basics of digital video compression and optimization next.<br />

Digital Video Compression Concepts: Bit Rate, Data Streaming, SD, HD, UHD<br />

Let’s begin with the primary or standard resolutions that are used in commercial video. These also happen to be<br />

common device screen resolutions, probably because if the screen pixel resolution matches the video pixel resolution<br />

that is being played full screen on a screen, there will be zero scaling, which can cause scaling artifacts. Before high<br />

definition came along, video was standard definition (SD) and used a vertical resolution of 480 pixels. VGA is an SD<br />

resolution, and 720 × 480 could be called wide SD resolution. High definition (HD) video comes in two resolutions,<br />

1,280 × 720, which I call pseudo HD, and 1,920 × 1,080, which the industry calls true HD. Both HD resolutions<br />

feature a 16:9 aspect ratio and are used in TVs and iTVs, smartphones, tablets, e-book readers, and game consoles.<br />

There is also an ultra high definition (UHD) resolution out now that features 4,096 × 2,160 pixels.<br />

Video streaming is a more complicated concept than resolution, as it involves playing back video data over a wide<br />

expanse, such as the one between your <strong>Java</strong> 8 game application and the remote video data server that will hold your<br />

potentially massive digital video assets. Furthermore, the device that your <strong>Java</strong> game application is running on will<br />

be communicating in real time with remote data servers, receiving video data packets as the video plays (it is termed<br />

streaming because the video is streaming from the video server, over the Internet, and into the hardware device).<br />

Video streaming is supported by the MPEG-4 H.264 AVC format codec (encoder-decoder pair).<br />

The last concept that you need to understand is bit rate. Bit rate is the key setting used in the video compression<br />

process, as bit rates represent your target bandwidth, or the data pipe size that is able to accommodate a certain<br />

number of bits streaming through it every second. The bit-rate setting should also take into consideration the CPU<br />

processing power that exists within any given <strong>Java</strong>-capable device, making your digital video’s data optimization even<br />

more challenging. Fortunately, most devices these days feature dualcore or quadcore CPUs!<br />

114<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!