Java & J2EE Page 8 - Gaming Development Setup |
As described in Chapter 3, the paint() method is called whenever the screen needs to be repainted, usually once per game loop during animation. The calling of the paint() method is managed by the superclass AnimatedApplet and is triggered by the repaint requests made in the update() method. graphics.setColor ( BACKGROUND_COLOR ); graphics.fill ( componentBounds ); The background is always drawn first. icon.paintIcon ( component, graphics, targetRectangle.x, 0 ); The target image is painted. graphics.setColor ( BALL_COLOR ); graphics.fillOval ( The ball is drawn. graphics.setColor ( SCORE_COLOR ); graphics.drawString ( Finally the score text is drawn. Because the score is drawn after the ball in the paint() method, the score cannot be occluded by the ball. Notice that no game state is updated in the paint() method and no graphics are painted in the update() method. It is a sin to do otherwise. Modifying the BuildAfter playing with the game example and reviewing its source code, you might want to go ahead and use it as a template for a game of your own invention. I recommend that you do so using an incremental approach, building and testing after each small change. The first change you might want to make is to change the package name for the class. Even this one-line change to the code can be frustrating if you do not consider the simultaneous changes that need to be made to the Ant build file. The following code documents the required changes. <target name="basics_prep" depends="init"> If you add or remove media files for the game, you must modify target basics_prep. <target name="basics" depends="basics_prep"> If you change the package or class name, you must modify target basics. This wraps up the Java game programming basics example. If any of it is a bit of a mystery, be assured that all will be explained in subsequent chapters. Later chapters will also make the point that while this code serves as a useful example and an initial template, there are a number of improvements that could be made. SummaryIn this chapter, you learned how to compile the example code used throughout the book using the development build tool Ant. You also learned about other development tools such as image and audio editors. I identified sources for code and multimedia you can incorporate into your games, and explained Open Source licensing terms. I documented the source code for an example game demonstrating the Java game programming basics for reuse as a template. In the following chapters, I describe the classes available to you within the reusable game library in detail. Further ReadingEckstein, Robert. XML Pocket Reference, 2nd edition. Sebastopol, CA: O’Reilly & Associates, 2001. Feldman, Ari. Designing Arcade Computer Game Graphics. Plano, TX: Wordware Publishing, 2000. Fishman, Stephen. The Public Domain: How to Find & Use Copyright-Free Writings, Music, Art & More. Berkeley, CA: Nolo Press, 2001. Fishman, Stephen. Web & Software Development: A Legal Guide, 3rd edition. Berkeley, CA: Nolo Press, 2002. (1). http://www.opensource.org/
blog comments powered by Disqus |
|
|
|
|
|
|
|