Suchen und Finden
Service
Beginning iPhone Games Development
PJ Cabrera, Peter Bakhirev, Ian Marsh, Ben Smith, Eric Wing, Scott Penberthy, Stuart Marsh, Roderick
Verlag Apress, 2010
ISBN 9781430226000 , 728 Seiten
Format PDF, OL
Kopierschutz Wasserzeichen
Title Page
Title Page
Copyright Page
Copyright Page
Contents at a Glance
4
Table of Contents
Table of Contents
About the Authors
13
About the Technical Reviewer
About the Technical Reviewer
Acknowledgments
16
Introduction
17
Chapter 1 A Revolutionary Gaming Platform: Games for Everyone, Anytime, Anywhere
Chapter 1 A Revolutionary Gaming Platform: Games for Everyone, Anytime, Anywhere
The Ever-Present iPhone
18
Mass Appeal—There’s a Gamer Born Every Minute
19
User Interfaces—Death of the D-Pad
21
Connectivity—Plays Well with Others
22
User Data—This Time It’s Personal
23
Device Performance—A Multimedia Powerhouse
25
Dev Kit? You’re Holding It!
26
Innovation—Good Things Come from Small Developers
Innovation—Good Things Come from Small Developers
Summary
28
Chapter 2 Developing iPhone Games: Peeking Inside the iPhone Toolbox
Chapter 2 Developing iPhone Games: Peeking Inside the iPhone Toolbox
Development Tools and Environment
29
UIKit
30
Quartz 2D and Core Animation
31
OpenGL ES
32
Audio APIs
33
Networking
34
Summary
35
Chapter 3 Moving Images on a Small Screen—UIKit Controls
Chapter 3 Moving Images on a Small Screen—UIKit Controls
A Quick Introduction to Cocoa Touch
36
The Objective-C Language
37
A Brief Objective-C Example
37
Using an Objective-C Class
41
Memory Management in Objective-C
43
Cocoa Touch and the UIKit Framework
44
Introducing UIView
45
The Frame Property
45
The Background Color and Alpha Properties
47
The Center Property
47
Building a Simple Game
48
Creating an Xcode Project
48
Creating the IVBricker User Interface
50
Examining the Main Window File
50
Examining the View Controller File
52
Setting View Properties
52
Adding Components to the View
53
Adding Code to the View Controller
55
Connecting a Property with a Component
56
Snazzy Graphics Make the Grade
57
Adding the Image
57
The Illusion of Motion
59
Rocking and Grooving with User Input
61
Handling Accelerometer Input
63
Handling Touchscreen Input
64
When Objects Collide
65
Failure Conditions
66
Winning Conditions
72
Loading and Displaying Images Programmatically
72
Creating the Grid of Bricks
74
Detecting image View Collisions
76
Changing the Timer to CADisplayLink
79
The End?
81
Application Delegate Events
82
Application Termination
82
Application Interruptions
83
Low Memory Warnings
83
Saving and Loading Game State
84
Managing Memory with a Custom Image Loader
86
Animating Images
87
Using the UIImageView Animation Properties
87
Using NSTimer for Animation
89
Using CADisplayLink for Animation
90
Summary
93
Chapter 4 She Shoots, She Hits, She Scores!
Chapter 4 She Shoots, She Hits, She Scores!
Quartz 2D Game Overview
94
Every Artist Needs a Canvas
96
Your First Graphic with Quartz 2D
104
Saving and Restoring the Context
105
Adding Color
107
Sprites
108
Creating the Sprite Class
108
Using the Sprite Class
114
Which Way Is Up?
117
Changing to Landscape Orientation
117
Centering the Origin
119
Vector Art
120
Creating the VectorSprite Class
121
Using the VectorSprite Class
124
Flipbook Animations
127
Creating the AtlasSprite Class
128
Modifying the Sprite Class
133
Using the AtlasSprite Class
134
Heads-Up Displays
138
Creating the TextSprite Class
138
Using the TextSprite Class
144
Asteroids Game Architecture
145
The Asteroids Game Loop
145
The Asteroids Model
146
The Asteroids View
148
The Asteroids Game Controller
149
Conclusion
151
Chapter 5 Flipping Out and Sweeping Away with Core Animation
Chapter 5 Flipping Out and Sweeping Away with Core Animation
Core Animation Sample Project Overview
153
Animating UIViews
155
Simple Movement
158
Animation Curves
159
Reverse and Repeat
161
Delay, Ease-In, and Ease-Out
163
UIView Transforms
164
UIView Transitions
166
Animating Core Animation Layers
168
Implicit Animations
169
Timing Functions
169
Layer Animation Transitions
170
Fade
171
Move In, Push, and Reveal
173
Summary
174
Chapter 6 OpenGL Basics: Wrapping Your Head Around the OpenGL API
Chapter 6 OpenGL Basics: Wrapping Your Head Around the OpenGL API
What Is OpenGL ES and Why Do I Care?
175
Understanding the 3D World
176
Matrix Basics: Taking the Red Pill
178
Bringing It All Together
181
Matrix Types
181
The Model and the Model Matrix
182
The View Matrix
182
The Projection
182
The Viewport
182
Stateful API
182
Rendering Basics
183
The Basic Game Template
184
Wrapping the CAEAGLLayer in a View: EAGLView
186
First Steps: The Init Method
187
Frame Buffers, Render Buffers, and Depth Buffers
189
Seeing into the OpenGL World
192
Drawing and Rendering
197
How to Draw Stuff with OpenGL
198
The Scene and Mesh Objects
198
Pushing and Popping Matrixes
201
Putting Your Objects in the Scene
201
Moving Objects
201
Scaling Objects
202
Spinning Objects
202
Defining Your Object in 3D Space
204
Vertex and Color Information
204
Understanding Triangles
206
The Game Loop and the Timer
208
The Input Controller
213
The App Delegate
214
Summary
214
Chapter 7 Putting It Together: Making a Game in OpenGL
Chapter 7 Putting It Together: Making a Game in OpenGL
Space Rocks! Game Design
216
Getting Started with the Template
218
Rotation Makes the World Go 'Round
219
3D Point Upgrade
222
Adding Buttons
224
Creating a Button Object
225
Working with Vertex Data
226
Storing Buttons
228
Detecting Touches
231
Wiring Up the Buttons
236
Building a Better Spaceship
237
Going Mobile
237
Adding the Spaceship
237
Adding and Removing Scene Objects
240
Falling Off the Edge of the Screen
242
Space Rocks!
243
Adding Missiles
247
Firing Missiles
247
Removing Unwanted Missiles
248
Making Nicer Buttons
249
Collision Detection
251
What Is a Collision?
251
Collision-Detection Techniques
252
Optimized Collision Detection
253
Radius-to-Radius Collision Check
254
Collisions on the Rocks
257
Centroid and Radius
257
Colliders and Collidees
259
Take the Red Pill: The Transform Matrix
259
The Collider Object
261
The Collision Controller Object
263
Back to the Scene Controller
264
Scene Object Updates
265
Collision Checking Redux
268
Summary
271
Chapter 8 The Next Steps: Atlases, Sprites, and Particles—Oh My!
Chapter 8 The Next Steps: Atlases, Sprites, and Particles—Oh My!
Textures and Texture Atlases
273
What Is a Texture Anyway, and Why Do I Care?
274
Getting Image Data into OpenGL
275
Binding Textures
279
UV Is Not Bad for Your Skin
280
You Get a Textured Quad!
281
Say Hello to the Texture Atlas
284
Switching the Old and Busted for the New Hotness
288
A Nicer User Interface
288
Colors with Textures
290
Sprite Animation
292
Frame Rate Independence
294
Animations for Everything
298
From 2D to 3D
299
It’s Only One More D—What’s the Big Deal?
300
Where Do 3D Models Come From?
301
From Modeler to Screen
302
What Is Normal?
303
Standardizing on GL_TRIANGLES
303
Textures Plus Models
305
Shadows Define Shape
307
Depth Buffer and Face Culling
310
Collision Detection Tweaks
312
Particle Systems Add Life to Your Game
313
What Is a Particle System?
313
A Lot of Random Numbers
314
The Nitty-Gritty of a Particle System: Particles
315
Particle Emitters and You
316
Tuning Our System
323
Particle Systems for Everything
324
What the Future Holds: Shaders
325
Summary
325
Chapter 9 Introduction to Core Audio
Chapter 9 Introduction to Core Audio
Audio Services Provided by Core Audio
327
Audio Units
328
Audio File Services
329
Audio File Stream Services
329
Audio Conversion Services
329
Extended Audio File Services
329
Audio Session Services
330
System Sound Services
330
Audio Queue Services
330
AVFoundation
331
OpenAL
331
The Core Audio Frameworks
332
Codecs and File Formats
333
Codecs Supported by Core Audio
334
File Formats Supported by Core Audio
335
Using afconvert to Convert Between Formats
336
Hardware-Accelerated Codecs: Restricted and Unrestricted Codec Groups
Hardware-Accelerated Codecs: Restricted and Unrestricted Codec Groups
Codec and File Format Suggestions
338
Alerts and Vibration: Introducing System Sound Services
Alerts and Vibration: Introducing System Sound Services
The Case Against System Sound Services for General Sound Effects
The Case Against System Sound Services for General Sound Effects
A System Sound Services Example
341
A Comment on Asynchronous Playback
347
Setting Policies for Your Audio: Introducing Audio Session Services
Setting Policies for Your Audio: Introducing Audio Session Services
Boilerplate Code and Procedures for Using Audio Session Services
Boilerplate Code and Procedures for Using Audio Session Services
Detecting Hardware and Getting Properties
352
Easy Audio Playback in Objective-C with AVFoundation
Easy Audio Playback in Objective-C with AVFoundation
Mission Complete…but Our Princess Is in Another Castle!
Mission Complete…but Our Princess Is in Another Castle!
Chapter 10 Making Noise with OpenAL
Chapter 10 Making Noise with OpenAL
OpenAL Overview
366
What OpenAL Supports
366
Some History of OpenAL
366
My Story and Goals for Audio Coverage
370
Roadmap for the Audio Coverage
371
Setting Up Basic Sound in OpenAL
372
Setting Up an Audio Session
373
Opening a Device
374
Advanced OpenAL Tip: Specifying OpenAL Devices
375
Creating a Context
377
Advanced Tip: Using Attribute Lists
377
Activating the Context
378
Generating Sound Sources
379
Generating Data Buffers
380
Loading Sound Data from Files
380
Submitting Sound Data to OpenAL Data Buffers
384
Advanced OpenAL Tip: The alBufferDataStatic Extension
384
Attaching a Data Buffer to a Sound Source
386
Playing Sound
386
Shutting Down and Cleaning Up
387
Cow Launched!
388
Exposing Flaws and the Missing Details
388
Adding More Sounds
390
Problems to Notice
394
OpenAL Error Checking
395
Audio Session Interruptions
396
OpenAL Extensions for iPhone OS
400
Performance Notes
400
OpenAL Source Limits: “It’s a Secret to Everybody”
402
Sound Resource Manager: Fixing the Design
404
Overview of the Resource Manager
405
Initial Cleanup
407
The Sound File Database (Cache System)
412
OpenAL Source Management (Reserving and Recycling)
416
Integration with Space Rocks!
420
SoundDidFinishPlaying Callbacks
424
Final Integration Steps for Space Rocks!
426
Handling When All Available Sources Are Exhausted
431
Final Demo Embellishments
431
Save Point Reached
434
Chapter 11 3D Audio—Turning Noise into Game Sounds
Chapter 11 3D Audio—Turning Noise into Game Sounds
The Design of OpenAL: Sources, Buffers, and Listeners
The Design of OpenAL: Sources, Buffers, and Listeners
Limits of 3D Audio in OpenAL
438
Integrating the Listener into Space Rocks!
438
Creating the Listener Class
439
Picking the Designated Driver
440
Adding Positions to Sounds
441
Handling Initial Positioning on Creation
443
Disabling Distance Attenuation
444
Working Around an alDistanceModelBug: Disabling Attenuation on a Per-Source Basis
Working Around an alDistanceModelBug: Disabling Attenuation on a Per-Source Basis
Listener Orientation
446
Right-Handed Coordinate Systems and the Right-Hand Rule
446
Unit Circle, Polar-to-Rectangular Coordinates, Phase Shifting, and Trigonometric Identities
Unit Circle, Polar-to-Rectangular Coordinates, Phase Shifting, and Trigonometric Identities
Integration into Space Rocks!
451
Source Direction and Cones
453
Inner Cone, Outer Cone, and Transitional Zone
453
Implementation Time
455
Velocity and the Doppler Effect
456
Velocities and Scaling Factors
458
Doppler Effect Example Time
459
Distance Attenuation
460
Attenuation Models
461
Inverse Distance
461
Inverse Distance Clamped
462
Linear Distance
462
Linear Distance Clamped
463
Exponential Distance
464
Exponential Distance Clamped
465
Distance Attenuation Parameters
466
Picking a Distance Model
467
Back to Space Rocks!
468
Using Relative Sound Properties to Selectively Disable 3D Effects
Using Relative Sound Properties to Selectively Disable 3D Effects
Achievement Unlocked: Use All OpenAL 3D Features
473
Chapter 12 Streaming: Thumping, Pulse-Quickening Game Excitement
Chapter 12 Streaming: Thumping, Pulse-Quickening Game Excitement
Music and Beyond
475
iPod Music Library (Media Player Framework)
478
Playing iPod Music in Space Rocks!
480
Adding a Media Item Picker
482
Shake It! (Easy Accelerometer Shake Detection)
485
Audio Streaming
486
AVFoundation-Based Background Music for Space Rocks!
487
The Playback Sound Controller
488
Integration into Space Rocks!
491
OpenAL Buffer Queuing Introduction
493
Initialization
495
Unqueuing
497
Queuing
498
Buffer Underrun
499
Pausing
500
Fast Forwarding and Rewinding
500
Startup Number of Buffers and Filling the Queue
500
How to Choose the Number and Size of Buffers
501
OpenAL-Based Background Music for Space Rocks!
502
A New Buffer Data Class for Streaming
502
Unqueue the Processed Buffers
507
Queue a New Buffer If Necessary
508
Handle a Buffer Underrun
509
Handle EOF and Finished Playing
509
OpenALSoundController Changes
510
BBSceneController Integration
513
Analysis: Number of Buffers and Buffer Sizes
514
Star Power Ready!
515
OpenAL Speech for Space Rocks!
515
EWSoundSourceObject: Finishing the implementation
517
BBSceneController: Adding a New UFO
517
UFO: Taunting and Callbacks
518
The alBufferDataStatic Crashing Bug
521
Work-Arounds
523
Audio Queue Services Based Background Music for Space Rocks!
Audio Queue Services Based Background Music for Space Rocks!
Rewind and Looping
526
Audio Session Interruptions
527
Perfect Full Combo!
528
Audio Capture
528
Audio Capture APIs
530
AVFoundation: File Recording with AVAudioRecorder
531
OpenAL: Capture Oscilloscope
536
The Capture APIs
539
ALC Device Enumeration
539
Capturing Audio
540
Back to OpenGL
543
Vertex Buffer Objects
543
Some Notes on OpenGL and OpenAL Optimization
545
The End of the Audio Road
547
Chapter 13 Networking for iPhone Games: Introduction
Chapter 13 Networking for iPhone Games: Introduction
Meet the Network
549
Network Interfaces
550
TCP/IP
550
Bonjour
552
iPhone SDK and Networking
552
Sockets and Connections
552
BSD Socket API
553
CFNetwork
553
NSNetServices
553
GameKit
GameKit
Summary
554
Chapter 14 Going Head to Head
Chapter 14 Going Head to Head
Hello Pong!
555
Using Peer Picker to Find a Human Opponent
556
What Does It Look Like?
561
How Does It Work?
564
Making the Connection
565
Sending and Receiving Messages
568
Rolling the Dice
569
Ready…Set…Go!
577
Hits and Misses
579
The Paddle Comes Alive
587
Game Over: Handling Disconnects
592
Summary
593
Chapter 15 Party Time
Chapter 15 Party Time
8 x 3 = ?
595
Starting Point
595
Where Are We Going?
598
What’s in the Structure?
599
Making Connections
601
Introducing the Connection and Stream Objects
601
Connection Initialization
603
Closing and Cleanup
604
Reading Data
605
Writing Data
608
Handling Stream Events
609
The Complete Picture
609
Socket Servers
610
The SocketServer Class
610
Socket Server Initialization
611
Publishing via Bonjour
614
Starting and Stopping
615
Finding Servers via Bonjour
616
Looking for Servers
617
Connecting to Servers
619
Final Details
621
Implementing the Game Client
625
Tracing the Logic
625
Choosing the Network Message Format
628
Making It Talk
630
Hooking It Up
633
Implementing the Game Server
634
Managing Players
635
Laying It Out
637
Initialization
642
Players Joining and Leaving
643
Starting and Stopping Game Rounds
644
Collecting and Processing Answers
647
Hooking It Up
648
Summary
648
Chapter 16 Connecting with the Outside World
Chapter 16 Connecting with the Outside World
Challenges
649
Au Revoir, Bonjour!
649
No GameKit Peer-to-Peer for You!
650
Server, interrupted
650
Lag
651
It’s All Greek to Me…
651
And a Bunch More
652
Basics of Online Game Play
653
Client/Server Games
653
Connecting to a Game Server Without Bonjour
654
Peer-to-Peer Games
655
Something About Reinventing the Wheel
656
Like a Drop in the Ocean
657
Making Games More Social
657
Sharing High Scores Online
657
Chasing Ghosts
659
Chatting
659
Summary
660
Chapter 17 Putting It All Together: Now Comes the Fun Part
Chapter 17 Putting It All Together: Now Comes the Fun Part
What We’ve Covered
661
Some Game Design Tips
662
Wrapping It Up
663
Index
664