scaling, 342
world space vs. model space, 334–335
hierarchical systems with, 520–526
perspective projection, 502–504
collision detection and object representation in, 581–584
bounding shapes in 3D programming, 581–583
GameObject3D and DynamicGameObject3D classes, 583–584
lighting in OpenGL ES API, 538–556
enabling and disabling, 543
limitations of, 556
accelerometer state, reading, 146–151
AccelerometerHandler handler, AndroidInput implementation and, 202–204
accelHandler.getAccelX( ) method, 220
accelHandler.getAccelY( ) method, 220
accelHandler.getAccelZ( ) method, 220
action games, and arcade games, 58–61
active matrices, and matrix modes, 298
activities
starting programmatically, 123–124
Activity class, 121, 124, 128, 152, 235–236, 292
activity.getAssets( ) method, 198
Activity.isFinishing( ) method, 130
Activity.onCreate( ) method, 37, 126, 159, 167
Activity.onStart( ) method, 126
Activity.onStop( ) method, 126
ADB (Android Debug Bridge) tool, 50–51
ADB command, 51
addScore( ) method, 245
ADT (Android Development Tools) plug-in, 28–30
advance( ) method, 264
alpha blending, in OpenGL ES, 329–333
alpha compositing, and blending, 91–94
AmbientLight( ) method, 553, 628
Android 1.5, optimizing OpenGL ES, 347
Android Debug Bridge (ADB) tool, 50–51
Android Development Tools (ADT) plug-in, 28–30
Android Market website, putting game on, 642–645
marketing, 645
Product Details section, 644
Publish button, 645
Publishing Options panel, 644–645
Android Open Source Project, 4
Android Package Kit (APK) files, 38, 41, 79, 635, 637–641, 650
connecting device, 39
writing application code, 36–38
JDK, 26
Android Virtual Devices (AVDs), 39–40
AndroidAudio interface, and AndroidSound and AndroidMusic interfaces, 197–202
AndroidAudio.newMusic( ) method, 199
AndroidAudio.newSound( ) method, 198
AndroidBasicsStarter activity, 121–123, 126
AndroidBasicsStarter class, 122–123, 125, 129
AndroidFastRenderView class, 231–234
AndroidFileIO.getAssets( ) method, 235, 293
AndroidGame class, 100, 234–238, 290–293
AndroidGame parameter, 232
AndroidGame.setScreen( ) method, 238
AndroidGraphics interface, and AndroidPixmap interface, 221–234
AndroidFastRenderView class, 231–234
handling different screen sizes and resolutions, 221–226
AndroidGraphics.getAssets( ) method, 235
AndroidInput class, 212, 236, 293
AndroidInput implementation, 202–204, 219–221
AndroidManifest.xml file, 44, 109, 117
AndroidMusic class, 199–200, 202
AndroidMusic interface, and AndroidAudio and AndroidSound interfaces, 197–202
AndroidPixmap interface, AndroidGraphics interface and, 221–234
AndroidFastRenderView class, 231–234
handling different screen sizes and resolutions, 221–226
AndroidSound class, 199
AndroidSound interface, and AndroidAudio and AndroidMusic interfaces, 197–202
angle( ) method, 365, 368, 538
Animation class, 428
AnimationScreen class, 430
AnimationTest class, 430
API class, 365
APIs (Application Programming Interfaces), 121–192
accessing external storage, 154–157
shared preferences, 158
input device handling, 132–151
multitouch events, 132–136, 143
processing key events, 143–146
reading accelerometer state, 146–151
reading compass state, 151
playing sound effects, 159–162
programming
APK (Android Package Kit) files, 38, 41, 79, 635, 637–641, 650
application and window management modules, 74
<application> element, 110–111
Application Programming Interfaces. See APIs
connecting device, 39
<application> element, 110–111
<manifest> element, 109
<uses-feature> element, 114–116
<uses-permission> element, 113–114
<uses-sdk> element, 116
market filters, 119
steps to set up game project, 117–118
writing code for, Hello World project, 36–38
arcade games, action games and, 58–61
art style, for Super Jumper game, 436–437
art styles
and backstory, for Droid Invaders game, 589–590
assetDescriptor.getLength( ) method, 200
assetDescriptor.getStartOffset( ) method, 200
AssetManager.openFd( ) method, 159, 198
assets
for Droid Invaders game, 593–596
sound and music, 596
fetching from disk with LoadingScreen class, 246
text with bitmap fonts, 443–445
texture atlas, 447
Assets class
for Droid Invaders game, 597–599
Assets.invaderModel.bind( ) method, 629–630
Assets.invaderModel.getNumVertices( ) method, 630
Assets.invaderModel.unbind( ) method, 630
Assets.invaderTexture.bind( ) method, 629–630
Assets.load( ) method, 455
Assets.music.pause( ) method, 459, 602, 606
Assets.music.play( ) method, 459, 606
Assets.playSound( ) method, 460, 473
Assets.reload( ) method, 455, 602
Assets.shieldModel.bind( ) method, 630
Assets.shieldModel.getNumVertices( ) method, 630
Assets.shieldModel.unbind( ) method, 630
Assets.shipModel.bind( ) method, 629
Assets.shipModel.getNumVertices( ) method, 629
Assets.shipModel.unbind( ) method, 629
Assets.shipTexture.bind( ) method, 629
Assets.shotModel.bind( ) method, 630
Assets.shotModel.getNumVertices( ) method, 631
Assets.shotModel.unbind( ) method, 631
physics of sound, 80
playing sound effects, 159–162
quality and compression, 81–82
setting volume controls, 158–159
Audio interface, 82
Audio( ) method, 98
Audio.newMusic( ) method, 82
Audio.newSound( ) method, 83
AVDs (Android Virtual Devices), 39–40
awesomePic.dispose( ) method, 102
awesomePic.getHeight( ) method, 102
awesomePic.getWidth( ) method, 102
background.reload( ) method, 452, 599
backstories, and art style, 589–590
ballVertices.bind( ) method, 377, 404, 414
ballVertices.unbind( ) method, 377, 404, 414
batcher.beginBatch( ) method, 424
batcher.drawSprite( ) method, 419
batcher.endBatch( ) method, 419, 424, 432, 460, 465, 490, 604, 607, 625, 631
beginBatch( ) method, 421
benchmarking, Super Jumper game, 492–493
best practices, 192
bind( ) method, 322, 354, 497–498, 550–551, 560
Bitmap class, 178
bitmap fonts, text with, 443–445
Bitmap.Config file, 182
Bitmap.drawBitmap( ) method, 224
BitmapFactory.decodeStream, 315, 318–319
BitmapFactory.Options class, 179, 321
BitmapFactory.Options( ) method, 179, 181
bitmap.getConfig( ) method, 178, 229, 560
bitmap.getHeight( ) method, 178, 227, 559–560
bitmap.getWidth( ) method, 178, 227, 559–560
Bitmap.recycle( ) method, 179, 183, 227, 317–319, 559–560
disposing of, 179
loading and examining, 178–179
BitmapTest activity, 180
blending
Bob class, in Super Jumper game, 471–473
bob.hitPlatform( ) method, 477, 479
bob.hitSpring( ) method, 480
bob.hitSquirrel( ) method, 479
bobModel.bind( ) method, 355
bobModel.unbind( ) method, 355
BobScreen.present( ) method, 344, 346
BobScreen.resume( ) method, 349
BobTest method, 425
bobTexture.bind( ) method, 340, 349–350
bobTexture.reload( ) method, 350
Bob.update( ) method, 477
Boolean.parseBoolean, 244, 453–454, 600
bottomText.length( ) method, 488
bounding shapes
in 3D programming, 581
bounding sphere overlap testing, 582–583
for collision detection, 379–383
bounds.width( ) method, 185
broad phase, collision detection, 390–391
buffer.asFloatBuffer( ) method, 302, 327
buffer.asIntBuffer( ) method, 426, 497, 550
buffer.asShortBuffer( ) method, 327, 497, 550
buffering, double, vsync and, 86–87
buffer.order, 302, 327, 497, 550
builder.appendevent.getKeyCode( ) method, 145
builder.appendevent.getX( ) method, 134
builder.appendevent.getY( ) method, 134
builder.toString( ) method, 134, 145
ByteArrayOutputStream( ) method, 153
ByteBuffer.allocateDirect( ) method, 309
byteBuffer.asFloatBuffer( ) method, 303, 306, 309, 311, 314, 319, 324
byteBuffer.asShortBuffer( ) method, 323, 325
byteBuffer.orderByteOrder.nativeOrder( ) method, 303, 306, 309, 311, 314, 319, 323–325
ByteOrder.nativeOrder( ) method, 302, 327, 497, 550
calculateInputAcceleration( ) method, 623–624
calledglOrthof( ) method, 301
camera.getDirection( ) method, 567
camera.getLookAt( ) method, 628
camera.getPosition( ) method, 567, 628
camera.setViewportAndMatrices( ) method, 409, 414, 424, 432
cam.setViewportAndMatrices( ) method, 489
Cannon class, 392, 400, 402, 413
CannonTest class, 368
cannonVertices.bind( ) method, 377, 404, 414
cannonVertices.draw( ) method, 414
cannonVertices.unbind( ) method, 377, 404, 414
Canvas class, 170, 172–173, 179, 225, 558, 560
canvas, hardware-accelerated rendering with, 191–192
Canvas.drawBitmap( ) method, 225, 230, 233
canvas.drawCirclecanvas.getWidth( ) method, 176
Canvas.drawLine( ) method, 230
Canvas.drawPoint( ) method, 230
Canvas.drawRect( ) method, 230
Canvas.drawRGB( ) method, 229
Canvas.getClipBounds( ) method, 233
canvas.getHeight( ) method, 172, 176
canvas.getWidth( ) method, 172, 176, 185–186
Castle class, in Super Jumper game, 468
Caveman class, 430
Caveman.update( ) method, 431
challenges, device seeding program, 5–6
checkBitten( ) method, 265, 269
checkCastleCollisions( ) method, 478, 480
checkCollisions( ) method, 477–478
checkGameOver( ) method, 477, 481
checkInvaderCollisions( ) method, 616–617
checkItemCollisions( ) method, 478, 480
checkPlatformCollisions( ) method, 478–479
checkShotCollisions( ) method, 616, 618–619
checkSquirrelCollisions( ) method, 478–480
children.size( ) method, 523
circles
drawing, 175
Class.forName( ) method, 124
cleanupResources( ) method, 98
clearDynamicCells( ) method, 398
Coin class, in Super Jumper game, 467–468
coins.size( ) method, 478, 480
colliders.size( ) method, 402
circle and rectangle collision, 387–389
and object representation in 3D programming, 581–584
GameObject3D and DynamicGameObject3D classes, 583–584
CollisionScreen class, 409
CollisionTest class, 402
CollisionTest file, 409
Color class, 174
colors
description of, 87
specifying for vertices, 309–312
combining, of 2D transformations, 343–345
compass state, reading, 151
CompassHandler handler, 204–221
AndroidInput implementation, 219–221
KeyboardHandler handler, 207–211
MultiTouchHandler class, 215–219
SingleTouchHandler class, 212–215
TouchHandler interface, 212
compatibility, across all devices, 19–20
compositing alpha, and blending, 91–94
compression
Config class, 229
connectivity, permanent, 21–22
Context interface, 124, 147, 152, 159
Context parameter, 219
context.getAssets( ) method, 152, 181, 196
Context.getExternalFilesDir( ) method, 245
continuous rendering, with SurfaceView class, 186–192
checking surface validity, 187–188
reason for using, 187
SurfaceHolder class and locking, 187
coordinate systems, screen resolution and, 172–173
crateTexture.bind( ) method, 568
crateTexture.reload( ) method, 567
createCube( ) method, 515–516, 524, 553–554, 566–567, 579
createMipmaps( ) method, 559–560
createObject( ) method, 206–207, 209, 213, 216
createWindowAndUIComponent( ) method, 98
cube.bind( ) method, 516, 525, 555, 568
CubeScreen class, 515
CubeTest class, 515
cube.unbind( ) method, 516, 526, 555, 569
currentTime( ) method, 98
Dalvik Debugging Monitor Server (DDMS), LogCat system and, 48–50
DDMS (Dalvik Debugging Monitor Server), LogCat system and, 48–50
debugging
density, 222
descriptor.getLength( ) method, 163, 165
descriptor.getStartOffset( ) method, 163, 165
device seeding program, challenges, 5–6
compatibility across all, 19–20
connecting, 39
hardware specifications, 12–13
next generation of devices, 17–18
DirectionalLight( ) method, 553, 628
disable( ) method, 546
dispose( ) method, 96, 200, 247, 251, 257, 322, 432, 488, 561, 626
distSquared( ) method, 386, 389, 538
double-buffering, vsync and, 86–87
drawGameOverUI( ) method, 274, 276
drawLine( ) method, 230
drawPausedUI( ) method, 274–276
drawPixel( ) method, 230
drawPixmap( ) method, 228, 230–231
drawReadUI( ) method, 276
drawReadyUI( ) method, 274–275
drawRect( ) method, 230
drawRunningUI( ) method, 274–276
drawText( ) method, 184, 186, 256, 276, 457
drawWorld( ) method, 275
sound and music, 596
backstory and art style, 589–590
screens and transitions, 590
Shield, 608
DroidInvaders activity, 604
DroidInvaders class, 599
dynamicCells[cellId].size( ) method, 398
dynamicCells[i].clear( ) method, 397
DynamicGameObject class, 392, 433, 583
DynamicGameObject3D class, GameObject3D class and, 583–584
eat( ) method, 264
Eclipse platform
installing
overview, 28
editor.commit( ) method, 158
e.getMessage( ) method, 156, 161, 165
enable( ) method, 546, 548, 555
endBatch( ) method, 421
engines, frameworks and, 648–650
Environment class, 155
Environment.getExternalStorageDirectory( ) method, 155–156, 196
Environment.getExternalStorageState( ) method, 155–156
e.printStackTrace( ) method, 122, 201
ES method, 290, 306, 347, 352, 426, 529
EulerCamera class, 562, 565–566
EulerCamera.getDirection( ) method, 566
EulerCamera.rotate( ) method, 568
event logging, LogCat system, 48–50
event.getAction( ) method, 134, 137–138, 140–141, 144, 161, 209, 214, 216
event.getPointerCount( ) method, 140, 216
event.getUnicodeChar( ) method, 145, 209
events.size( ) method, 603, 606, 622–624
explosionTexture.reload( ) method, 599
external storage, accessing, 154–157
externalDir.getAbsolutePath( ) method, 156
factory.createObject( ) method, 206
FastMath class, 365
FastMath.cos( ) method, 366, 376
FastMath.sin( ) method, 366, 376
FastRenderView class, 190, 231
FastRenderView.pause( ) method, 189–190, 233
FastRenderView.resume( ) method, 189–190, 232
accessing external storage, 154–157
shared preferences, 158
file I/O, 79
FirstTriangleScreen class, 306
FirstTriangleTest class, 306
flip( ) method, 304
float lines.size( ) method, 575
FloatBuffer, working around bug in, 426–427
floatBuffer.clear( ) method, 303
floatBuffer.flip( ) method, 303
Font class, in Super Jumper game, 456–457
Font.drawText( ) method, 464–465
fonts
loading, 183
foundObjects.clear( ) method, 398
foundObjects.contains( ) method, 398
FPSCounter( ) method, 622
fpsCounter.logFrame( ) method, 349–350, 353, 355
FPSCounter.logFrame( ) method, 492
fpsCounter.logFrame( ) method, 625
frame-independent movement, 103–104
frame rate, optimizing OpenGL ES, 345–347
frame rates, frame-independent movement, 103–104
frameBuffer.getHeight( ) method, 231
frameBuffer.getWidth( ) method, 231
framebuffers, pixels, rasters and, 84–85
frameworks, and engines, 648–650
free( ) method, 207
freeObjects.removefreeObjects.size( ) method, 206
AndroidAudio, AndroidSound, and AndroidMusic interfaces, 197–202
AndroidGraphics and AndroidPixmap interfaces, 221–234
AndroidFastRenderView class, 231–234
handling different screen sizes and resolutions, 221–226
AndroidInput implementation and AccelerometerHandler handler, 202–204
CompassHandler handler, 204–221
AndroidInput implementation, 219–221
KeyboardHandler handler, 207–211
Game interface, 99–101, 197, 234–235, 237, 290, 358
game over state, in Super Jumper game, 481
game screen, in Super Jumper game, 481–489
game world, of Super Jumper game, 438–441
game.getAudio( ) method, 246, 451–452, 599
Game.getCurrentScreen( ) method, 100
game.getCurrentScreen( ) method, 233
Game.getFileIO( ) method, 197, 315, 318–319, 575
game.getGLGraphics( ) method, 297, 306, 319, 324, 339, 368, 401, 431, 458, 577
game.getGraphics( ) method, 102, 243, 246, 248, 250, 254, 256, 274–276
game.getInput( ) method, 248, 252, 307, 375, 459, 484–485, 605, 622, 624
Game.getStartScreen( ) method, 100, 234, 306
GameObject class, 392, 466–467
GameObject3D class, and DynamicGameObject3D class, 583–584
GameObject(float)Math.random( ) method, 393, 401
gamers, casual and hardcore, 22
GameScreen class, 251, 270–277, 481, 492, 620–626, 632
GameScreen.present( ) method, 486
GameScreen.render( ) method, 492
Game.setScreen( ) method, 100–101, 249
GC activity, 621
generateInvaders( ) method, 615–616
generateLevel( ) method, 474–475
generateShields( ) method, 615–616
action and arcade games, 58–61
tower-defense games, 61
getAccelX( ) method, 77, 203, 220, 485
getAccelY( ) method, 77, 203, 220, 624
getAccelZ( ) method, 78, 203, 220
getAssets( ) method, 153, 161, 165
getAudio( ) method, 99, 237, 296
getConfig( ) method, 181
getCurrentScreen( ) method, 100, 238, 296
getDeltaTime( ) method, 372–374, 580
getDirection( ) method, 564
getFileIO( ) method, 99, 237, 295
getGL( ) method, 291
getGLGraphics( ) method, 295, 297, 311, 319, 330, 339, 375, 401, 431, 458
getGraphics( ) method, 99, 237, 295
getHeight( ) method, 95–96, 172, 227, 231, 235, 291
getInput( ) method, 99, 237, 295
getKeyEvents( ) method, 78, 205, 211, 248, 256, 307, 369, 402, 462, 464
getKeyFrame( ) method, 429
getLookAt( ) method, 572
getNumIndices( ) method, 579
getNumVertices( ) method, 579
getOrientation( ) method, 150
getPosition( ) method, 563, 572
getPotentialColliders( ) method, 396, 398
getPreferences( ) method, 197
getResources( ) method, 235–236
getRoll( ) method, 205
getRotation( ) method, 150
getStartScreen( ) method, 100, 234–235, 238, 242, 296, 339, 455, 552, 602
getTouchEvents( ) method, 205, 215, 219, 248, 307, 402, 462, 486, 622, 624
getTouchX( ) method, 215, 218, 367
getUp( ) method, 572
getWidth( ) method, 95–96, 172, 227, 231, 235, 291
getWindow( ) method, 168, 171, 176, 181, 185, 188, 235, 289, 292
getWindowManager( ) method, 235
g.getHeight( ) method, 249, 274
g.getWidth( ) method, 274
glBindTexture( ) method, 315–316
glBlendFunc( ) method, 329–330
glClear( ) method, 290, 308, 506
glClearColor( ) method, 290, 349
glClearColor.nextFloat( ) method, 289, 297
glColorPointer( ) method, 310–312, 314, 347, 549
glDisableClientState( ) method, 318, 328
glDrawArrays( ) method, 305, 308, 320, 324, 328, 333, 348, 356
glDrawElements( ) method, 310, 328, 333, 347–348, 356
glEnable( ) method, 318, 320, 349, 505, 514, 632
glEnableClientState( ) method, 304, 308–309, 314, 318, 324, 353, 355
glFrustumf( ) method, 503
GLGame class, 290–297, 306–309, 409, 601
GLGame interface, 626
glGame.getFileIO( ) method, 321, 558
GLGame.getGLGraphics( ) method, 296, 307
glGame.getGLGraphics( ) method, 321, 558
GLGame.getInput( ) method, 367
glGenTextures( ) method, 317
GLGraphics method, 296
glGraphics.getGL( ) method, 297, 328, 340, 376, 408, 424, 604, 624, 626, 628
glGraphics.getHeight( ) method, 301, 307, 500, 504, 508, 516, 525, 554–555, 566
glGraphics.getWidth( ) method, 349, 369, 402, 408, 504, 508, 525, 566, 568, 628
glIdentityf( ) method, 537
glLightModelfv( ) method, 543
glLoadIdentity( ) method, 338, 344, 350, 353, 369, 506, 516, 519, 555, 572
glMaterialfv( ) method, 548
glMatrixMode( ) method, 353, 519
glNormalPointer( ) method, 549, 551
glOrtho( ) method, 504
glOrthof( ) method, 299–300, 334, 336, 343, 404, 406, 409, 433, 503
glPopMatrix( ) method, 519–520, 522–523, 569, 629–631
glPushMatrix( ) method, 519–520, 522–523, 569, 629–631
glRotatef( ) method, 341–342, 349, 352, 369, 515, 520, 534, 537, 555
glScalef( ) method, 341–343, 349, 352, 556
GLScreen, in Super Jumper game, 457–458
GLScreen.update( ) method, 484
GLSurfaceView method, 289
GLSurfaceView.onPause( ) method, 288
GLSurfaceView.onResume( ) method, 288
GLSurfaceView.Renderer interface, 292
glTexCoordPointer( ) method, 314
glTexEnv( ) method, 330
glTexParameterf( ) method, 316
glTranslate( ) method, 426
glTranslatef( ) method, 336, 338, 343, 356, 377, 517, 520, 526, 537, 631
GLU.glLookAt( ) method, 529
GLU.gluPerspective( ) method, 504, 529
gluLookAt( ) method, 529, 552, 555, 572
gluPerspective( ) method, 503, 555, 562, 564
GLUtils class, 316
glVertexPointer( ) method, 304–305, 308, 310–311, 314, 324, 347, 498, 549
glView.getHeight( ) method, 291
glView.getWidth( ) method, 291
glView.onPause( ) method, 289, 295
glView.onResume( ) method, 289, 293
glViewport( ) method, 349
glViewportf( ) method, 406
glXXXPointer( ) method, 347, 353, 355
Android Open Source Project, 4
challenges, device seeding program, 5–6
alpha compositing and blending, 91–94
disposing of, 179
loading and examining, 178–179
colors
description of, 87
continuous rendering in UI thread, 169–172
circles, 175
lines, 174
image formats and compression, 90–91
rasters, pixels, and framebuffers, 84–85
rendering
hardware-accelerated with canvas, 191–192
screen resolution and coordinate systems, 172–173
vsync and double-buffering, 86–87
wake locks, 167
Graphics interface, 95, 228, 290
Graphics( ) method, 98
Graphics.clear( ) method, 95–96, 250
Graphics.drawLine( ) method, 96
Graphics.drawPixel( ) method, 95–96
Graphics.drawPixmap( ) method, 96, 104, 241, 253
Graphics.drawRect( ) method, 96
Graphics.getHeight( ) method, 96, 367, 407
Graphics.getWidth( ) method, 96, 367, 407
Graphics.newPixmap( ) method, 95, 247
guiCamera.setViewportAndMatrices( ) method, 569
guiCam.setViewportAndMatrices( ) method, 460, 463, 465, 487, 604, 606, 624–626
guiCam.touchToWorld.touchPoint.set.game.getInput( ) method, 623
hardware-accelerated rendering, with canvas, 191–192
hardware, specifications for, 12–13
headPixmap.getHeight( ) method, 275
headPixmap.getWidth( ) method, 275
writing application code, 36–38
HelloWorldActivity class, 38, 45, 123
help screens, in Super Jumper game, 461–463
helpImage.dispose( ) method, 462
HelpScreen class, 251
hierarchical systems, with matrices, 520–526
HierarchicalObject class, 522–524
solar system example, 521
HierarchicalObject class, 524, 526
HierarchicalObject.render( ) method, 524
HierarchicalObject.update( ) method, 524
HierarchyScreen.present( ) method, 530
high scores, and user settings, 243–245
high-scores screen, 253–257, 463–466
HighscoreScreen class, 255
hitPlatform( ) method, 472–473
hitSpring( ) method, 473
hitSquirrel( ) method, 472–473
holder.getSurface( ) method, 189, 232
holder.lockCanvas( ) method, 189, 233
I/O (Input/Output), file, 79
icons, defining for game, 119–121
IDEs (Integrated Development Environments), 25–33
Eclipse platform
JDK, 26
image formats, and compression, 90–91
in.close( ) method, 229, 244, 322, 453, 455, 559, 578, 601
indices.flip( ) method, 325
indices.limit( ) method, 579
INF file, 39
multitouch events, 132, 136–143
processing key events, 143–146
reading accelerometer state, 146–151
reading compass state, 151
single-touch events, processing, 132–136
Input interface, 78, 202, 205, 207, 212, 219
Input( ) method, 98
Input/Output (I/O), file, 79
Input.getAccelX( ) method, 78
Input.getAccelY( ) method, 78
Input.getAccelZ( ) method, 78
Input.getKeyEvents( ) method, 210
Input.getTouchEvents( ) method, 568
Input.getTouchX( ) method, 78
Input.getTouchY( ) method, 78
Input.isKeyPressed( ) method, 78, 210
Input.isTouchDown( ) method, 78
inputStream.close( ) method, 153, 181
in.readLine( ) method, 244, 453–454, 600
insertDynamicObject( ) method, 397
insertStaticObject( ) method, 397
Integer.parseInt.in.readLine( ) method, 244, 453–454
Integrated Development Environments. See IDEs
Intent class, 124
invader.kill( ) method, 618
invaders.size( ) method, 616–618, 629
invaderTexture.reload( ) method, 599
invalidate( ) method, 169–171, 176, 181, 185
isFinishing( ) method, 295
isGameOver( ) method, 619, 623
isKeyPressed( ) method, 210
isTouchDown( ) method, 215, 218
items.reload( ) method, 452, 599
JAR file, 35
Java class, 8, 33, 122, 124, 129
Java Development Kit (JDK), 26
Java method, 347
Java object, 315
JDK (Java Development Kit), 26
key events, processing, 143–146
KeyboardHandler class, 208
KeyboardHandler handler, 207–211
KeyboardHandler.getKeyEvents( ) method, 209, 211, 215
KeyEvent class, 78, 143, 207–208, 213
KeyEvent( ) method, 209
KeyEvent type, 210
keyEventPool.newObject( ) method, 209
keyEventsBuffer.clear( ) method, 210
keyEvents.clear( ) method, 210
keyEvents.size( ) method, 210
keyHandler.getKeyEvents( ) method, 221
kill( ) method, 610–611, 614, 618
Level parameter, 41
LifeCycleTest activity, 129, 131
lighting, in OpenGL ES API, 538–556
enabling and disabling, 543
limitations of, 556
LightScreen class, 552
line.length( ) method, 254, 257, 276
lines
drawing, 174
lines.size( ) method, 576
Linux kernel, 7
ListActivity class, 122
ListAdapter interface, 122
listener.coin( ) method, 480
listener.explosion( ) method, 618
listener.highJump( ) method, 480
listener.hit( ) method, 479
listener.jump( ) method, 479
listener.shot( ) method, 616, 619
load( ) method, 159, 162, 244, 321–322, 558–560, 598, 601
LoadingScreen class
fetching assets from disk with, 246–247
fetching from disk with LoadingScreen class, 247
loadTextFile( ) method, 154
loadTexture( ) method, 320
location awareness, 647
locking
SurfaceHolder class and, 187
wake locks, 167
Log class, 129
LogCat system, and DDMS, 48–50
logFrame( ) method, 346
main activity
for Droid Invaders game, 601–602
for Droid Invaders game, 602–604
main( ) method, 108
MainMenu class, 238
MainMenu( ) method, 98
MainMenu.update( ) method, 238
manager.getSensorListSensor.TYPE_ACCELEROMETER.size( ) method, 147–148, 203
<manifest> element, 109
<application> element, 110–111
<manifest> element, 109
<uses-feature> element, 114–116
<uses-permission> element, 113–114
<uses-sdk> element, 116
market filters, 119
steps to set up game project, 117–118
market filters, 119
marketing, 645
Material class, 548
Material( ) method, 553
Math class, 365
Math.maxhighScores[i].length( ) method, 464
Math.random( ) method, 431
matrices
and 2D transformations, 335–336
hierarchical systems with, 520–526
Matrix class, 534, 537, 562, 584
matrix modes, and active matrices, 298
Matrix.multiplyMV( ) method, 537
Matrix.rotateM( ) method, 537
Matrix.setIdentityM( ) method, 537
MediaPlayer class, 163
MediaPlayer( ) method, 163, 165, 200
mediaPlayer.isLooping( ) method, 201
mediaPlayer.isPlaying( ) method, 164, 200–201
mediaPlayer.pause( ) method, 163, 165–166, 201
mediaPlayer.prepare( ) method, 163, 165, 200–201
mediaPlayer.release( ) method, 164–165, 200
mediaPlayer.setDataSourceassetDescriptor.getFileDescriptor( ) method, 200
mediaPlayer.setDataSourcedescriptor.getFileDescriptor( ) method, 163, 165
mediaPlayer.start( ) method, 163–166, 200–201
mediaPlayer.stop( ) method, 164–165, 200, 202
methodFloat.floatToRawIntBits( ) method, 426
big market with small developers, 22–23
casual and hardcore gamers, 22
ubiquity of mobile devices, 20–21
model space, vs. world space, 334–335
Model-View-Controller design pattern. See MVC
OBJ loader, implementing, 574–579
MotionEvent.ACTION_MASK event, 138
MotionEvent.getAction( ) method, 133, 137–138
MotionEvent.getPointerCount( ) method, 138, 141
MotionEvent.getY( ) method, 138
movement
time-based, in Mr. Nom game, 265–266
keeping track of user settings and high scores, 243–245
screens
keeping track of user settings and high scores, 243–245
LoadingScreen class, fetching assets from disk with, 246–247
MrNomGame class, 242
MrNomGame.getStartScreen( ) method, 246
multiplayer functionality, 648
multitouch events
overview, 132
MotionEvent.ACTION_MASK event, 138
pointer IDs and indices, 137–138
MultiTouchHandler class, 215–219, 236
music
sound and, for Droid Invaders game, 596
music.play( ) method, 451–452, 599
MVC (Model-View-Controller) design pattern, 258–269
Snake and SnakePart classes, 260–265
Stain class, 260
ending game, 267
placing stains, 266
time-based movement of Mr. Nom, 265–266
MyAwesomeGame class, 100
MySuperAwesomeGame class, 102–103
MySuperAwesomeGame.getStartScreen( ) method, 102
MySuperAwesomeStartScreen class, 102
MySuperAwesomeStartScreen( ) method, 102
MySuperAwesomeStartScreen.dispose( ) method, 103
MySuperAwesomeStartScreen.pause( ) method, 103
MySuperAwesomeStartScreen.present( ) method, 103
MySuperAwesomeStartScreen.resume( ) method, 103
MySuperAwesomeStartScreen.update( ) method, 103–104
narrow phase, collision detection, 385–390
circle and rectangle collision, 387–389
nativeOrder( ) method, 302, 327, 497, 550
newMusic( ) method, 198
newPixmap( ) method, 229
newSound( ) method, 199
normalized device space, 284
OBJ file, 574, 578–580, 584, 595
OBJ format, Wavefront, 573–574
OBJ loader, implementing, 574–579
Object( ) method, 292
object representation, and collision detection in 3D programming, 581–584
GameObject3D and DynamicGameObject3D classes, 583–584
ObjLoader.load( ) method, 579
onAccuracyChanged( ) method, 149, 204
OnClickListener.onClick( ) method, 38
OnCompletionListener interface, 200–201
OnCompletionListener.onCompletion( ) method, 200, 202
onCreate( ) method, 37, 122, 126, 130, 145, 166, 172, 185, 236, 293
onDraw( ) method, 169–171, 176, 182, 185
onDrawFrame( ) method, 288, 290, 294
onKey( ) method, 143, 145, 210–211, 214
OnKeyEventListener.onKeyEvent( ) method, 208
OnKeyListener interface, 145, 208
OnKeyListener.onKey( ) method, 209
onPause( ) method, 126, 128, 162, 166, 188, 236, 288, 293, 295, 602
onResume( ) method, 126, 128, 130, 150, 166, 188, 190, 288, 293, 599
onSensorChanged( ) method, 147, 149, 204
onSurfaceChanged( ) method, 287, 290, 294
onSurfaceCreate( ) method, 293, 455
onSurfaceCreated( ) method, 287–288, 290, 602
onTouch( ) method, 133–136, 141, 162, 214–215, 218
OnTouchListener interface, 132, 134, 136, 141, 161, 212–213
open-source programming, Android Open Source Project, 4
scaling, 342
world space vs. model space, 334–335
perspective projection, 502–504
Android 1.5, 648
enabling and disabling, 543
limitations of, 556
colors, specifying for vertices, 309–312
defining projection matrix, 298–301
matrix modes and active matrices, 298
orthographic projection with glOrthof, 299–300
defining viewport, 298
and direct NIO buffers, 302–303
GLGame class, 290–297, 306–309
normalized device space, 284
Android 1.5, 347
possible rendering issues, 347–349
reducing calls, 352
reducing texture size, 351–352
removing unnecessary state changes, 349–351
disposing of textures, 317
enabling texturing, 318
optimizing, OpenGL ES, 345–356
Android 1.5-347, 347
possible rendering issues, 347–349
reducing calls, 352
reducing texture size, 351–352
removing unnecessary state changes, 349–351
Options( ) method, 228
orthographic projection, with glOrthof, 299–300
out.close( ) method, 245, 454–455, 601
overlap testing, bounding sphere, 582–583
overlapCircles( ) method, 386
OverlapTester class, 582
Paint( ) method, 174, 176, 185, 228
parts.get.parts.size( ) method, 264
pause( ) method, 83, 101, 250, 257, 277, 307, 462, 488, 516, 626
paused( ) method, 277
perspective projection, 502–504
object falling example, 373–378
pixels
rasters, framebuffers and, 84–85
Pixmap parameter, 230
Pixmap.dispose( ) method, 97
Pixmap.getFormat( ) method, 96
Pixmap.getHeight( ) method, 96
Pixmap.getWidth( ) method, 96
Platform class, in Super Jumper game, 469–471
Platform int type, 470
platform.pulverize( ) method, 479
platforms.size( ) method, 477, 479
play( ) method, 83, 162, 199, 201
playback, recording and, 80–81
PNG file, 182
pointer IDs, and pointer indices, 137–138
PointLight class, 547
PointLight( ) method, 553, 566
PoolObjectFactory.newObject( ) method, 206
PowerManager.FULL_WAKE_LOCK type, 167
PowerManager.newWakeLock( ) method, 167
precision, of z-buffer, 510–511
preferences, shared, 158
present( ) method, 233, 250, 320, 349, 403, 424, 517, 569, 620, 625
presentGameOver( ) method, 487–488, 624, 626
presentLevelEnd( ) method, 487–488
presentPaused( ) method, 487–488, 624–625
presentReady( ) method, 487
presentRunning( ) method, 487, 624–626
primitives, in OpenGL ES, 333–334
Product Details section, 644
programming
audio quality and compression, 81–82
physics of sound, 80
setting volume controls, 158–159
file I/O, 79
frame-independent movement, 103–104
game and screen interfaces, 99–101
alpha compositing and blending, 91–94
continuous rendering in UI thread, 169–172
image formats and compression, 90–91
rasters, pixels, and framebuffers, 84–85
screen resolution and coordinate systems, 172–173
vsync and double-buffering, 86–87
wake locks, 167
modules
application and window management, 74
projection matrix, defining in OpenGL ES, 298–301
matrix modes and active matrices, 298
orthographic projection with glOrthof, 299–300
projections, in OpenGL ES, 282–284
Publish button, 645
becoming registered developer, 636–637
putting game on Android Market website, 642–645
marketing, 645
Product Details section, 644
Publish button, 645
Publishing Options panel, 644–645
Publishing Options panel, 644–645
pulverize( ) method, 471
rand.nextFloat( ) method, 289, 297, 337, 475, 479
Random( ) method, 171, 267, 289, 297, 337, 474, 615
Random.nextFloat( ) method, 476
reader.close( ) method, 156
reader.readLine( ) method, 156, 578
recording, and playback, 80–81
Rect class, 180
Rect( ) method, 181, 185, 228, 232
Rectangle class, 583
rectangles
registered developers, becoming, 636–637
reload( ) method, 322, 452, 560, 599
removeObject( ) method, 397
render( ) method, 340, 487, 489–490, 523, 526, 607, 625, 628, 632
renderBackground( ) method, 489–490
renderCastle( ) method, 490, 492
renderer.render( ) method, 487
rendering
continuous
with SurfaceView class, 186–192
hardware-accelerated, with canvas, 191–192
alignment and boundaries of, 184
putting it all together, 184–186
renderItems( ) method, 490–492
renderObjects( ) method, 489–490
renderPlatforms( ) method, 490–491
renderSquirrels( ) method, 490, 492
renderThread.join( ) method, 189, 233
renderThread.start( ) method, 189, 232
RenderView class, 171–172, 182, 189
renderView.pause( ) method, 188, 236
renderView.resume( ) method, 188, 236
RenderViewTest activity, 171
resolutions, screen sizes and, 221–226
resume( ) method, 101–102, 247, 251, 350, 354, 377, 465, 500, 626
rotate( ) method, 366, 422, 535, 537, 564
rotating, 2D transformations, 341–342
run( ) method, 189–190, 232–233
Runnable interface, 190
scaling, 2D transformations, 342
score.length( ) method, 274
scores, high, and user settings, 243–245
scoreString.length( ) method, 488
Screen class, 99–100, 246, 308
Screen interface, 238
screen interface, game interface and, 99–101
screen resolution, and coordinate systems, 172–173
screen sizes, and resolutions, 221–226
Screen.dispose( ) method, 101, 236, 294
Screen.pause( ) method, 101, 236, 294
Screen.present( ) method, 101, 231
Screen.render( ) method, 288
Screen.resume( ) method, 101, 236–237, 293, 296
screens
Screen.update( ) method, 101, 231, 266
SDKs (software development kits), 10–11
SensorEventListener interface, 149, 203
SensorManager class, 151
SensorManager.getRotationMatrix( ) method, 151
setDirection( ) method, 547
setFilters( ) method, 322
setIndices( ) method, 327, 550
setLooping( ) method, 202
setMatrices( ) method, 564, 572, 629
setPosition( ) method, 547
Settings class
for Droid Invaders game, 600–601
settings screen, for Droid Invaders game, 604–607
Settings.loadgame.getFileIO( ) method, 246
Settings.loadgetFileIO( ) method, 602
Settings.load( ) method, 247
Settings.savegame.getFileIO( ) method, 250, 276, 460, 485, 606
setVertices( ) method, 327, 498, 500, 550
setViewportAndMatrices( ) method, 408–409
circles, 175
lines, 174
shared preferences, 158
Shield class, 608
shields.size( ) method, 618, 630
shipTexture.reload( ) method, 599
shoot( ) method, 619
shortBuffer.flip( ) method, 323
shots.size( ) method, 617–619, 631
SimpleRenderer( ) method, 289
Shield, 608
single-touch events, processing, 132–136
SingleTouchHandler class, 212–215
SingleTouchHandler.getTouchEvents( ) method, 215, 219
SingleTouchHandler.onTouch( ) method, 218
Snake class, and SnakePart class, 260–265
snake.advance( ) method, 266, 268
snake.eat( ) method, 269
SnakePart class, Snake class and, 260–265
snake.parts.size( ) method, 268–269, 275
social media, integration with, 647
software development kits (SDKs), 10–11
solar system example, 521
sound
and music, for Droid Invaders game, 596
physics of, 80
SoundPool.load( ) method, 159–160, 162
SparseArray class, 192
SpatialHashGrid class, 400, 481
SpatialHashGrid.getCellIds( ) method, 396, 398
SpatialHashGrid.getPotentialColliders( ) method, 403
Spring class, in Super Jumper game, 466–467
springs.size( ) method, 480
Sprite class, 418
SpriteBatcher class, 423, 428, 595
SpriteBatcher.beginBatch( ) method, 419
SpriteBatcher.drawSprite( ) method, 418–419, 422, 446
SpriteBatcher.endBatch( ) method, 419
sprites
measuring performance of, 425–426
working around bug in FloatBuffer, 426–427
SQLite database, 154
Squirrel class, in Super Jumper game, 468–469
squirrels.size( ) method, 478–479
Squirrel.update( ) method, 471
stains, placing, 266
state changes, removing unnecessary, 349–351
stateChanged.notifyAll( ) method, 294
stateChanged.wait( ) method, 295
staticCells[cellId].size( ) method, 398
stop( ) method, 83, 164, 200, 202
storage, external, accessing, 154–157
String file, 79, 82, 196, 198, 319, 321, 454, 558, 575, 600
StringBuilder( ) method, 129, 133, 139, 144, 148, 156
String.byteStream.toByteArray( ) method, 153
sun.update( ) method, 530
text with bitmap fonts, 443–445
texture atlas, 447
Castle class, 468
collision detection in, 478–480
game over state, 481
SuperJumper class, 462
SuperJumper.getStartScreen( ) method, 458
super.onPause( ) method, 130, 165, 188, 236, 289, 295, 602
super.onResume( ) method, 130, 165, 188, 236, 293
SurfaceHolder class, and locking, 187
surfaceHolder.getSurface( ) method, 187
SurfaceHolder.lockCanvas( ) method, 187–188
surfaces, checking validity of, 187–188
SurfaceView class, 186–192, 231, 287
checking surface validity, 187–188
reason for using, 187
SurfaceHolder class and locking, 187
surfaceView.getHolder( ) method, 187
System.nanoTime( ) method, 232–233, 292–294, 346, 615, 619
targets.size( ) method, 403, 414, 424
targetVertices.bind( ) method, 403, 414
targetVertices.unbind( ) method, 403, 414
alignment and boundaries of, 184
with bitmap fonts, in Super Jumper game, 443–445
fonts
loading, 183
putting it all together, 184–186
text.length( ) method, 185, 457
text.toString( ) method, 156
texture atlas
in Super Jumper game, 447
Texture class, 325, 329, 331, 558, 584
disposing of textures, 317
enabling texturing, 318
optimizing, reducing size of, 351–352
texture.bind( ) method, 325, 414, 421, 514, 516, 525, 555
TexturedTriangleScreen class, 318
texture.reload( ) method, 349, 516, 553
textureRgba.bind( ) method, 331
textureRgb.bind( ) method, 331
textView.requestFocus( ) method, 144
textView.setTextbuilder.toString( ) method, 130, 139, 149
this.indices.clear( ) method, 327, 497, 550
this.indices.flip( ) method, 327, 497, 550
this.position.set(float)Math.random( ) method, 430
this.screen.dispose( ) method, 237, 296
this.screen.pause( ) method, 237, 296
this.velocity.set.Math.random( ) method, 430
this.vertices.clear( ) method, 327, 426, 497, 550
this.vertices.flip( ) method, 327, 426, 497, 550
time-based movement, in Mr. Nom game, 265–266
toFloatBuffer.put( ) method, 303
topText.length( ) method, 488
MultiTouchHandler class, 215–219
SingleTouchHandler class, 212–215
TouchHandler interface, 212
TouchEvent( ) method, 207, 213, 216
touchEventPool.newObject( ) method, 207, 214, 216–217
touchEventsBuffer.clear( ) method, 215, 218–219
touchEvents.clear( ) method, 215, 218
touchEvents.size( ) method, 215, 218, 249, 256, 273, 369, 402, 462, 484, 486
TouchHandler interface, 212–213
touchHandler.getTouchEvents( ) method, 220
touchPos.len( ) method, 376, 402
touchPos.sub(cannonPos).angle( ) method, 369, 376
touchPos.sub(cannon.position).angle( ) method, 402
TouchTest activity, 168
touchToWorld( ) method, 409
tower-defense games, 61
transitions, screens and, 67–72, 590
triangle meshes, 3D in OpenGL ES, 511–517
triangles, with OpenGL ES, 302–305
trigonometry, for vectors, 361–362
Typeface class, 186
Typeface.createFromAsset.context.getAssets( ) method, 183, 185
UI (User Interface)
assets, for Droid Invaders game, 593–594
thread, continuous rendering in, 169–172
unbind( ) method, 354, 498, 551–552
update( ) method, 238, 339, 369, 410, 471, 478, 523, 610, 615, 617
updateCoins( ) method, 478
updateGameOver( ) method, 274, 484, 486, 622, 624
updateLevelEnd( ) method, 484, 486
updatePaused( ) method, 273, 484–486, 622–623
updatePlatforms( ) method, 478–479
updateReady( ) method, 272, 484
updateRunning( ) method, 273, 485, 488, 623
updateSquirrels( ) method, 478
updateTextView( ) method, 139–140
USB driver, 26
user experience, designing, 63–72
screens and transitions, 67–72
User Interface. See UI
user settings, and high scores, keeping track of, 243–245
<uses-feature> element, 114–116
<uses-permission> element, 113–114
<uses-sdk> element, 116
triangle cannon example, 366–371
velocity.len( ) method, 373–374
Vertical Synchronization (vsync), and double-buffering, 86–87
vertices
Vertices class, 326–330, 353, 355, 357, 426, 495–496
Vertices.bind( ) method, 354–355, 369, 421, 500, 504, 506, 508
vertices.draw( ) method, 331, 335, 353–354, 509
vertices.flip( ) method, 303, 306, 309, 311, 314, 319, 324–325
vertices.limit( ) method, 579
vertices.position( ) method, 498
Vertices.setVertices( ) method, 426
Vertices.unbind( ) method, 354, 369, 421, 500, 504, 506, 508
viewport, defining in OpenGL ES, 298
View.requestFocus( ) method, 144, 209
volume controls, setting, 158–159
vsync (Vertical Synchronization), and double-buffering, 86–87
wake locks, 167
WakeLock class, 167
wakeLock.acquire( ) method, 167, 236, 293
wakeLock.release( ) method, 167, 236, 295
windowMgr.getDefaultDisplay( ) method, 150
ending game, 267
placing stains, 266
collision detection in, 478–480
game over state, 481
time-based movement of Mr. Nom, 265–266
World( ) method, 268, 272, 615, 621
world space, vs. model space, 334–335
world.coins.size( ) method, 491
WorldListener interface, 614
WorldListener( ) method, 483, 621
WorldListener.jump( ) method, 479
world.platforms.size( ) method, 491
WorldRenderer class, 482, 487, 489–492, 609
world.shot( ) method, 623
world.snake.turnLeft( ) method, 272
world.snake.turnRight( ) method, 272
world.springs.size( ) method, 491
world.squirrels.size( ) method, 492
World.update( ) method, 478, 481, 620
writer.close( ) method, 156
XML file, 110
z-buffer, 3D in OpenGL ES, 505–511
z-fighting, 3D in OpenGL ES, 510–511
ZBlendingScreen class, 508
ZBufferScreen class, 506
ZIP file, 28
3.138.106.225