Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 4 ■ an IntroduCtIon to Game desIGn: Game desIGn ConCepts, Genres, enGInes, and teChnIques

nature of 3D new media assets is an order of magnitude more complex than 2D new media assets, the same
thing applies to 3D games versus 2D games. 2D games do have an element of “rendering” called double
buffering where the next frame is composited in memory, before it is displayed on the screen. 3D rendering,
however, is actually creating the pixel color and alpha values, not simply organizing them in an X,Y
location. 3D rendering creates the pixel color values and X,Y locations from scratch, based on 3D geometry,
transformations, materials, shaders, mapping coordinates, light position, and camera position.
Next let’s take a look at the pro Java game design aspects and considerations for some of these core
gaming concepts in greater detail and look at some of the core optimization principles that apply across all
genres of games.


Game Components: 2D, 3D, Collision, Physics, and AI


Let’s take a look at the various game design concepts, aspects, and components that you will need to
understand in order to be able to build a game, as well as what Java (or JavaFX) packages and classes we
can use to implement these aspects of gameplay, which I like to term components of gameplay design and
development. These could include the gameplay elements themselves, commonly referred to in the game
industry as sprites for a 2D game or models for a 3D game, as well as the processing engines, which we will
either code ourselves or import preexisting Java code libraries for, such as artificial intelligence, physics
simulations, particle systems, inverse kinematics, or collision detection. I will spend some time covering
each of these and why they would be applicable to a pro Java game and some optimization considerations
that you should keep in mind if you decide to use any of these game components.


2D Sprites: The Foundation of Arcade-Style Gaming


Let’s start with the foundation of one of the oldest forms of electronic gameplay, the arcade game. The 2D
assets, called sprites, define our main character, projectiles used to damage the main character, treasures
collected by the main character, and the enemies that are firing these projectiles. Sprites are 2D graphics
elements and can be either static (fixed, a single image) or dynamic (animated, a seamless loop of several
images). Sprites can be either vector (shapes) or raster (image-based) assets. If they are image based, they
will usually be PNG32 and carry an alpha channel so that they can be composited over the rest of the game
design in real time and have the result look like it is digital video, that is, like it is being shot with a camera
and played on the screen rather than being composited in real time based on the game player’s input, which
is usually a game controller, keyboard keys, or iTV set remote control.
A sprite will be moved around on the screen based on programming logic that dictates how the game
is to function. Sprites need to be composited with background imagery and other gameplay elements in the
Scene Graph as well as with other players’ sprites, so the PNG32 graphics that are used to create the sprites
will need to support transparent backgrounds. This is also why I covered the topic of masking 2D objects—
to use as sprites for your games.
This is also why I introduced you to the concept of alpha channel transparency, in Chapter 2 , as we
will need to achieve this same end result with our sprites so that we achieve a seamless visual experience
with our game. We’ll be covering how to use GIMP to create graphics that use alpha channels later during
this book so you can create professional-level sprites that composite seamlessly with the rest of your game
graphics.
Since 3D models are all in the same rendered space together, the 3D rendering engine will take care of
this transparency factor for you, and you do not have to worry about having an alpha channel for each 3D
component of your game if you use 3D models instead of 2D sprites. Let’s take a look at 3D models next as a
follow-up to this point.

Free download pdf