Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 24 ■ Optimizing game assets and COde, and game prOfiling Using netBeans

Finally, let’s add one more section to this chapter taking a look at what other JavaFX 9 API classes we
might utilize to expand this i3D game further, as you ultimately will. You can import i3D models from a
third-party importer package (unfortunately, this is not yet “natively” a part of JavaFX, so I stuck with JavaFX
i3D APIs for this book) and add in digital video assets, as long as you optimize them carefully. Since JavaFX
9 Modules (Distribution Packaging) is not quite finished as yet (we are still a month, or more, away from
the Java 9 release). An appendix covering JavaFX 9 Modules (Game Distribution Packaging) will be made
available as part of the book’s downloadable source code once Oracle has released it. To download this book’s
source code, navigate to http://www.apress.com/9781484209745 and click the Download Source Code button.


Future Expansion: Add Digital Video and 3D Models


You can add even more complex new media to your i3D board game by using i3D import software from
the third-party web site InteractiveMesh.org and by adding digital video assets created using something
like Black Magic Design’s DaVinci Resolve 14. You can optimize your video using something professional
like Sorenson Media’s Squeeze Desktop Pro 11. This will give you more experience using JavaFX 9’s more
advanced digital video and 3D APIs.
One of the things I am going to do next is to refine the 2D startup code for the instructions, credits, legal
information, and so forth. Now that a game is prototyped, it may also be a good idea to revisit the splash
screen graphic as well. Remember that Pro Java 9 Games Development, especially i3D games, is a refinement
process, as the hundreds of new media components that make up the i2D and i3D game assets are often
refined to bring a game in line with the vision of the game developer artisan.
Once you have prototyped your game, you can do code optimizations like the ones we covered earlier
and even create different classes for different features or functions if that is necessary. My technical editor
agreed with me that extra classes were not needed for this game, as I was attempting to create an i3D board
game using the classes that were already coded in the JavaFX API. In fact I’m importing (using) 44 Java or
JavaFX classes to create this game, so just because I have one JavaFXGame master class tying everything
together, there are actually 45 classes creating this game. Forty-four of them have been previously created,
coded, and optimized by Sun Microsystems and later by Oracle after its acquisition of Sun. What I am
trying to do in this book is show how to create a Pro Java 9 Game, leveraging all the previous work by these
companies over the past decade by simply using the JavaFX API classes optimally and minimizing the
amount of actual work a developer has to do to create an i3D board game. As Oracle continues to improve
these classes, JavaFX 9 will continue to become a more powerful and impressive game engine, and ideally
iOS and Android 8 support will continue to evolve and improve.


Summary


In this final twenty-fourth chapter, we looked at various asset (digital image and digital audio) optimization,
as well as Java code optimization. We learned about the NetBeans Profiler and how to look at how much
system memory is being used to run our game. We also looked what percentage of the CPU is being used
to process our Java code and when garbage collection is loading our texture maps into (and out of ) system
memory. We also looked at when threads are being used to process memory locations, instructions, looping,
random number generation, and similar Java code instructions.
We also looked at some of the other things that we could refine in the game and add to the game in the
future in order to leverage JavaFX 9 classes even further. Just make sure to use the Profiler to keep an eye on
system memory and CPU usage. I use one of my “weak” (4GB, four-core AMD 3.11GHz Acer) workstations
so I am testing the code on a “submainstream” computer, while at the same time I have enough power and
memory to run NetBeans 9, Java 9, and JavaFX 9 smoothly. This is a testament to the efficiency of NetBeans
9, Java 9, and JavaFX.

Free download pdf