28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

Game Optimization: Balancing Static Elements with Dynamic<br />

Game optimization comes down to balancing static elements, which do not require processing in real time, with<br />

dynamic elements, which require constant processing. Too much dynamic processing, especially when it is not really<br />

needed, can make your game play jerky, or stilted. This is why game programming is an art form: it requires balance<br />

as well as great characters, a story line, creativity, illusion, anticipation, accuracy, and, finally, optimization.<br />

Some of the different game component considerations for optimization in a dynamic game are listed in Table 5-1.<br />

As you can see, there are a lot of areas of game play that can be optimized to make the processor’s workload<br />

significantly less “busy.” If you have even one of these primary dynamic game processing areas “run away” with the<br />

processor’s precious cycles per frame, this can greatly affect the user experience for your game. I will be getting into<br />

game terminology (sprites, collision detection, physics simulation, and so on) in the next section of the chapter.<br />

Table 5-1. Aspects of Game Play That Can Be Optimized to Minimize System Memory and Processor Cycle Usage<br />

Game Play Aspect<br />

Sprite position (Move)<br />

Collision detection<br />

Physics simulation<br />

Sprite animation<br />

Background animation<br />

Game play logic<br />

Scoreboard updates<br />

UI design<br />

Basic Optimization Principle<br />

Move sprites by as many pixels as possible to achieve smooth movement on the screen.<br />

Check for collisions between objects on the screen only when necessary (in close<br />

proximity).<br />

Minimize the number of objects in a scene that require physics calculations<br />

to be performed.<br />

Minimize the number of frames that need to be cycled to create an illusion of<br />

smooth animation.<br />

Minimize background areas that are animated so that the entire background looks<br />

animated but is not.<br />

Program game play logic (simulated or AI) to be as efficient as possible.<br />

Update scoreboard only when scoring, and minimize score updates to once per<br />

second maximum.<br />

Use a static UI design so that pulse events are not used for UI element<br />

positioning or CSS3.<br />

Considering all these game programming areas makes game programming an extremely tricky endeavor!<br />

It is important to note that some of these aspects work together to create a given illusion for the player. For<br />

instance, the sprite animation will create the illusion of a character running, jumping, or flying, but without<br />

combining that code with sprite positioning (movement) code, the reality of the illusion will not be achieved.<br />

To fine-tune an illusion, the speed of the animation (frame rate) and the distance moved (in pixels per frame) may<br />

need to be adjusted (I like to call this tweaked) to get the most realistic result. We will be doing this during Chapter 13.<br />

If you can move game elements (primary player sprite, objectile sprites, enemy sprites, background) a greater<br />

number of pixels a fewer number of times, you will save processing cycles. It is the moving part that takes processing<br />

time, not the distance (how many pixels are moved). Similarly, with animation, the fewer frames needed to achieve<br />

a convincing animation, the less memory will be required to hold those frames. Remember that you are optimizing<br />

memory usage as well as processing cycles. Detecting collisions is a major part of game programming logic; it is<br />

important not to check for collisions between game elements that are not “in play” (on the screen), or active, and that<br />

are not near each other.<br />

Forces of nature (physics simulations) and game play logic if it is not well coded (optimized), are the most<br />

processor intensive aspects. These are subjects I will cover later in the book, when you are more advanced<br />

(see Chapters 16 and 17).<br />

www.it-ebooks.info<br />

103

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

Saved successfully!

Ooh no, something went wrong!