Contents
Contents at a Glance
About the Authors
Acknowledgments
Introduction
Chapter 1: Android, the New Kid on the Block
A Brief History of Android
Fragmentation
The Role of Google
The Android Open Source Project
The Android Market
Challenges, Device Seeding, and Google I/O
Android's Features and Architecture
The Kernel
The Runtime and Dalvik
System Libraries
The Application Framework
The Software Development Kit
The Developer Community
Devices, Devices, Devices!
Hardware
The Range of Devices
Compatibility Across All Devices
Mobile Gaming Is Different
A Gaming Machine in Every Pocket
Always Connected
Casual and Hardcore
Big Market, Small Developers
Summary
Chapter 2: First Steps with the Android SDK
Setting Up the Development Environment
Setting Up the JDK
Setting Up the Android SDK
Installing Eclipse
Installing the ADT Eclipse Plug-In
A Quick Tour of Eclipse
Helpful Eclipse Shortcuts
Hello World, Android Style
Creating the Project
Exploring the Project
Writing the Application Code
Running and Debugging Android Applications
Connecting a Device
Creating an Android Virtual Device
Running an Application
Debugging an Application
LogCat and DDMS
Using ADB
Summary
Chapter 3: Game Development 101
Genres: To Each One's Taste
Casual Games
Puzzle Games
Action and Arcade Games
Tower-Defense Games
Innovation
Game Design: The Pen Is Mightier Than the Code
Core Game Mechanics
A Story and an Art Style
Screens and Transitions
Code: The Nitty-Gritty Details
Application and Window Management
Input
File I/O
Audio
Graphics
The Game Framework
Summary
Chapter 4: Android for Game Developers
Defining an Android Application: The Manifest File
The <manifest> Element
The Application Element
The <activity> Element
The <uses-permission> Element
The <uses-feature> Element
The <uses-sdk> Element
Android Game Project Setup in Ten Easy Steps
Market Filters
Defining the Icon of Your Game
Android API Basics
Creating a Test Project
The Activity Life Cycle
Input Device Handling
File Handling
Audio Programming
Playing Sound Effects
Streaming Music
Basic Graphics Programming
Best Practices
Summary
Chapter 5: An Android Game Development Framework
Plan of Attack
The AndroidFileIO Class
AndroidAudio, AndroidSound, and AndroidMusic: Crash, Bang, Boom!
AndroidInput and AccelerometerHandler
AccelerometerHandler: Which Side Is Up?
CompassHandler
The Pool Class: Because Reuse Is Good for You!
KeyboardHandler: Up, Up, Down, Down, Left, Right …
Touch Handlers
The MultiTouchHandler
AndroidInput: The Great Coordinator
AndroidGraphics and AndroidPixmap: Double Rainbow
Handling Different Screen Sizes and Resolutions
AndroidPixmap: Pixels for the People
AndroidGraphics: Serving Our Drawing Needs
AndroidFastRenderView: Loop, Stretch, Loop, Stretch
AndroidGame: Tying Everything Together
Summary
Chapter 6: Mr. Nom Invades Android
Creating the Assets
Setting Up the Project
MrNomGame: The Main Activity
Assets: A Convenient Asset Store
Settings: Keeping Track of User Choices and High Scores
LoadingScreen: Fetching the Assets from Disk
The Main Menu Screen
The HelpScreenClass(es)
The High-Scores Screen
Rendering Numbers: An Excursion
Implementing the Screen
Abstracting…
Abstracting the World of Mr. Nom: Model, View, Controller
The GameScreen Class
Summary
Chapter 7: OpenGL ES: A Gentle Introduction
What is OpenGL ES and Why Should I Care?
The Programming Model: An Analogy
Projections
Normalized Device Space and the Viewport
Matrices
The Rendering Pipeline
Before We Begin
GLSurfaceView: Making Things Easy Since 2008
GLGame: Implementing the Game Interface
Look Mom, I Got a Red Triangle!
Defining the Viewport
Defining the Projection Matrix
Specifying Triangles
Putting It Together
Specifying Per Vertex Color
Texture Mapping: Wallpapering Made Easy
Texture Coordinates
Uploading Bitmaps
Texture Filtering
Disposing of Textures
A Helpful Snippet
Enabling Texturing
Putting It Together
A Texture Class
Indexed Vertices: Because Re-use is Good for You
Putting It Together
A Vertices Class
Alpha Blending: I Can See Through You
More Primitives: Points, Lines, Strips, and Fans
2D Transformations: Fun with the Model-View Matrix
World and Model Space
Matrices Again
An Initial Example Using Translation
More Transformations
Optimizing for Performance
Measuring Frame Rate
The Curious Case of the Hero on Android 1.5
What's Making My OpenGL ES Rendering So Slow?
Removing Unnecessary State Changes
Reducing Texture Size Means Fewer Pixels to be Fetched
Reducing Calls to OpenGL ES/JNI Methods
The Concept of Binding Vertices
In Closing
Summary
Chapter 8: 2D Game Programming Tricks
Before We Begin
In the Beginning ... There Was the Vector
Working with Vectors
A Little Trigonometry
Implementing a Vector Class
A Simple Usage Example
A Little Physics in 2D
Newton and Euler, Best Friends Forever
Force and Mass
Playing Around, Theoretically
Playing Around, Practically
Collision Detection and Object Representation in 2D
Bounding Shapes
Constructing Bounding Shapes
Game Object Attributes
Broad-Phase and Narrow-Phase Collision Detection
An Elaborate Example
A Camera in 2D
The Camera2D Class
An Example
Texture Atlas: Because Sharing Is Caring
An Example
Texture Regions, Sprites, and Batches: Hiding OpenGL ES
The TextureRegion Class
The SpriteBatcher Class
Sprite Animation
The Animation Class
An Example
Summary
Chapter 9: Super Jumper: A 2D OpenGL ES Game
Core Game Mechanics
A Backstory and Art Style
Screens and Transitions
Defining the Game World
Creating the Assets
The UI Elements
Handling Text with Bitmap Fonts
The Game Elements
Texture Atlas to the Rescue
Music and Sound
Implementing Super Jumper
The Assets Class
The Settings Class
The Main Activity
The Font Class
GLScreen
The Main Menu Screen
The Help Screens
The High-Scores Screen
The Simulation Classes
The Game Screen
The WorldRenderer Class
To Optimize or Not to Optimize
Summary
Chapter 10: OpenGL ES: Going 3D
Before We Begin
Vertices in 3D
Vertices3: Storing 3D Positions
An Example
Perspective Projection: The Closer, the Bigger
Z-buffer: Bringing Order into Chaos
Fixing the Last Example
Blending: There's Nothing Behind You
Z-buffer Precision and Z-fighting
Defining 3D Meshes
A Cube: Hello World in 3D
An Example
Matrices and Transformations Again
The Matrix Stack
Hierarchical Systems with the Matrix Stack
A Simple Camera System
Summary
Chapter 11: 3D Programming Tricks
Before We Begin
Vectors in 3D
Lighting in OpenGL ES
How Lighting Works
Light Sources
Materials
How OpenGL ES Calculates Lighting: Vertex Normals
In Practice
Some Notes on Lighting in OpenGL ES
Mipmapping
Simple Cameras
The First-Person or Euler Camera
A Euler Camera Example
A Look-At Camera
Loading Models
The Wavefront OBJ Format
Implementing an OBJ Loader
Using the OBJ Loader
Some Notes on Loading Models
A Little Physics in 3D
Collision Detection and Object Representation in 3D
Bounding Shapes in 3D
Bounding Sphere Overlap Testing
GameObject3D and DynamicGameObject3D
Summary
Chapter 12: Droid Invaders: The Grand Finale
Core Game Mechanics
A Backstory and Art Style
Screens and Transitions
Defining the Game World
Creating the Assets
The UI Assets
The Game Assets
Sound and Music
Plan of Attack
The Assets Class
The Settings Class
The Main Activity
The Main Menu Screen
The Settings Screen
The Simulation Classes
The Shield Class
The Shot Class
The Ship Class
The Invader Class
The World Class
The GameScreen Class
The WorldRender Class
Optimizations
Summary
Chapter 13: Publishing Your Game
A Word on Testing
Becoming a Registered Developer
Signing Your Game's APK
Putting Your Game on the Market
Uploading Assets
Product Details
Publishing Options
Publish!
Marketing
The Developer Console
Summary
Chapter 14: What's Next?
Getting Social
Location Awareness
Multiplayer Functionality
OpenGL ES 2.0 and More
Frameworks and Engines
Resources on the Web
Closing Words
Index