If you’ve done some game development in the past, you may be pleasantly surprised to learn how simple the Android system makes this process when compared to traditional PC and console ga
Trang 2For your convenience Apress has placed some of the front matter material after the index Please use the Bookmarks and Contents at a Glance links to access them
Trang 3iii
Contents at a Glance
About the Author ix
About the Technical Reviewer x
Acknowledgments xi
Chapter 1: Setting Up Android 3.0 Java Development 1
Chapter 2: Creating Simple Games with Sprites and Movement 27
Chapter 3: Creating Gathering User Input 47
Chapter 4: Adding Sound Effects, Music, and Video 69
Chapter 5: One-Player Game with Obstacles 87
Chapter 6: A Ball and Paddle Game 103
Chapter 7: Building a Two-Player Game 121
Chapter 8: A One-Player Strategy Game Part I 137
Chapter 9: A One-Player Strategy Game Part II 151
Chapter 10: Publishing the Game 167
Appendix A: Testing Android Games on a Real Device 179
Index 181
Trang 4C H A P T E R 1
Setting Up Android 3.0 Java
Development
This book teaches you to create your own games for Android 3.0 tablets After reading and working
through its examples, you’ll have gained command over the sensors, touchscreen, network capabilities, and processing power of the many new tablet computers Does that sound daunting? It isn’t Instead of going through the drudgery of developing stodgy corporate apps that locate a store or present a coupon, you’ll know how to make fun and intriguing games If you’ve done some game development in the past, you may be pleasantly surprised to learn how simple the Android system makes this process when
compared to traditional PC and console game development
Although no book ever written can take you from newbie to game programming guru, the
foundation presented in this book will let you make any of your 2D game ideas into a reality This book makes the programming as simple as possible in order to concentrate on the more creative aspects of
game development
What Is Android?
Android is very special, and you’ll gain much more appreciation for it as you get into the programming The movement of many handset makers to create tablets running the Android OS created a huge market for the games you’ll make This section gives you a rundown of Android’s features and history
The Beginnings of Android
In 2003, Android began as a small Silicon Valley startup company with the aim to create a more
interactive and helpful interface for smartphones Google quickly snatched up the company in 2005 as part of its push to enter the mobile phone market After Google acquired it, the first Android OS was
soon released during 2007 In subsequent years, Android went through many revisions (more than seven major changes) that made it one of the leading operating systems for smartphones, with some saying
that Android has nearly 50% of mobile devices
The revisions to Android are very important to understanding how development works Google
worked hard to ensure backward compatibility in its version of Android; however, applications generally are designed to work for a select couple of Android editions to guarantee the best performance and user experience The version called Froyo is still the most popular for developers, but the later versions are
gaining steam as more modern devices like tablets require more powerful operating systems
The following list of Android versions, along with their current market share, illustrates which
Trang 5CHAPTER 1 SETTING UP ANDROID 3.0 JAVA DEVELOPMENT
2
the numbers Keep in mind that with the exception of Android 3.0, all versions of the OS were designed for phones exclusively:
• Android 1.5 Cupcake (2.3%)
• Android 1.6 Donut (3.0%)
• Android 2.1 Éclair (24.5%)
• Android 2.2 Froyo (65.9%)
• Android 2.3 Gingerbread (1.0%)
• Android 2.3.3 Gingerbread (3.0%)
• Android 3.0 Honeycomb (0.3%)
If you’re interested in checking the current market share of the various versions, go to
http://developer.android.com/resources/dashboard/platform-versions.html
After examining this list, many would say that you should be making games for Froyo because it has
a huge lead in market share over other versions The reason for Froyo’s prevalence is that it’s installed on many simpler older phones that can only get updated versions through a complicated process These devices will slowly become inconsequential as the newer versions take center stage To some extent, making games for the majority of users makes sense; however, every day new users are buying more modern phones that use the later versions Also, perhaps the most important point is that hundreds of thousands of apps are playable on the Froyo version, and it’s increasingly difficult to stand out
With that being said, this book teaches you to designs games for the latest edition (Honeycomb) for two reasons First, Honeycomb is the only version optimized for tablets, which are much more
immersive and fun than any smartphone Second, Android tablet computing is growing at a huge rate as more companies release tablets that can compete with Apple’s iPad With the failure of webOS, Android and iOS are the only contenders in the tablet market Microsoft has also come out with its own operating system, but it has not yet garnered significant market share Google’s often-quoted statement about 500,000 Android devices being registered each day gives you a sense of how fast this market is
expanding
Android 3.0 Features
Honeycomb is a huge advance from the previous Android versions Designed to utilize a much larger screen and more powerful processor, Android 3.0 lets developers expand their usually modest
smartphone games Many of the new features are user-interface changes that make the desktop
accessible to users with a screen that is several times bigger than a smartphone screen For example, typical phones have two- to three-inch screens, whereas tablets boast impressive nine- to ten-inch screens These updates are convenient; however, game developers concentrate more on the updates to speedier graphics rendering and the new sensors and network abilities of the operating system
Not all games use all of these features, but it’s crucial to consider their importance in designing unique games The larger screen is in itself an update worth noting The high-resolution screens demand artwork that is scalable and visually appealing Many Android tablets have landed on 1280 × 800 as their screen size This is comparable to the resolution that many computer screens still use In this case, the graphics must approximate the images used in computer games
Table 1-1 list major changes to Android 3.0 of particular interest to game developers
Trang 6About the Technical Reviewer
Jelani John is a freelance developer and animator from Brooklyn He enjoys
making games and playing with new technologies You can find him at www.jelanijohn.com
Trang 7xi
Acknowledgments
Frank Pohlmann, Editorial Director at Apress, gave me the tremendous opportunity to write this book I
am very grateful for your advice and coaching as we hashed out what the book would look like
A very special thanks to Anita Castro, the coordinating editor, who pushed me through the
sometimes arduous task of completing the chapters, graphics, and code for this book You gave me some incredible advice and were very patient with me throughout the process
Thank you to all of the editors and reviewers who worked on the project with me Your
technical advice, wordsmithing, and organizational ideas made this book immeasurably better
I have also had many great mentors and colleagues who prompted me to do what I thought was impossible Thank you to Dave Briccetti for introducing me to the art of teaching computer science Paul
Spinrad was an amazing editor for Make Magazine who inspired me to take on this project after I read
his two stunning books Paul gave me good pointers, was patient with me, and refused to get angry
despite my fickleness I am very grateful to you