Professional Documents
Culture Documents
Writing Real Time Games PDF
Writing Real Time Games PDF
For Android
Chris Pruett
May 2009
I work in Japan.
2009/090507e.pdf)
Proper game is feasible with one 20% engineer (thats me) for
six months and 1 full time artist for four months.
Quick Demo
Game Graph
MainLoop
InputSystem
11
GameObject
System
CameraSystem
RenderSystem
Game Graph
MainLoop
Render Component
Scroller Component
Render Component
Scroller Component
Render Component
Scroller Component
Render Component
Sprite Component
Animation Component
Physics Component
Collision Component
Movement Component
Gravity Component
Player Component
12
Layer 3
Layer 2
Layer 1
Player Game
Object
Background
Game Object
RenderSystem
CameraSystem
GameObject
System
InputSystem
13
Android activity.
Responsible for bootstrapping the game
and receiving input events.
Main Thread
Input Events
Surface Holder
Mostly dormant.
Blocking
Game
Thread
Rendering
Thread
Blocking
off commands to OpenGL every frame-knows nothing about the game content.
14
Hardware
15
Choose flexibility over speed every day of the week... until the
gameplay is damaged.
18
19
Use Traceview!
21
22
OpenGL ES
23
2D and 3D drawing.
Hardware accelerated on some platforms (like the G1).
10
50
100
500
1000
0 ms
24
91 ms
181 ms
272 ms
362 ms
25
The tile map layers are regular grids of 32x32 tiles. That
means 150 tiles to draw per layer on any given frame (worst
case).
Its the tile maps that eat frame time, either on the CPU or the
GPU, depending on the drawing method.
26
27
28
29
30
call, very few total calls to other GL commands (only four meta
tiles to draw per layer per frame).
31
32
33
Performance Tips
Touching the screen causes your app to be flooded with
MotionEvents.
This will kill your framerate.
Sleep in the onTouchEvent callback to slow the flood. 16 ms is
a good place to start.
Android 1.0 - 1.5 failed to throw errors if you try to use VBOs
with indirect buffers. Result: unpredictable crashes.
Solution is to just use direct buffers.
34
35
Questions?