没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
Beginning Android
Games
■ ■ ■
Mario Zechner
Beginning Android Games
Copyright © 2011 by Mario Zechner
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any
means, electronic or mechanical, including photocopying, recording, or by any information
storage or retrieval system, without the prior written permission of the copyright owner and the
publisher.
ISBN-13 (pbk): 978-1-4302-3042-7
ISBN-13 (electronic): 978-1-4302-3043-4
Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image we use the names, logos,
and images only in an editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of opinion as to whether or not
they are subject to proprietary rights.
President and Publisher: Paul Manning
Lead Editor: Steve Anglin
Development Editor: Matthew Moodie
Technical Reviewer: Robert Green
Editorial Board:
Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Jonathan
Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Jeff Olson, Jeffrey
Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic
Shakeshaft, Matt Wade, Tom Welsh
Coordinating Editor: Adam Heath
Copy Editors: Damon Larson, Jim Compton
Compositor: MacPS, LLC
Indexer: BIM Indexing & Proofreading Services
Artist: April Milne
Cover Designer: Anna Ishchenko
Distributed to the book trade worldwide by Springer Science+Business Media, LLC., 233 Spring
Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail
orders-ny@springer-sbm.com, or visit www.springeronline.com.
For information on translations, please e-mail rights@apress.com, or visit www.apress.com.
Apress and friends of ED books may be purchased in bulk for academic, corporate, or
promotional use. eBook versions and licenses are also available for most titles. For more
information, reference our Special Bulk Sales–eBook Licensing web page at
www.apress.com/info/bulksales.
The information in this book is distributed on an “as is” basis, without warranty. Although every
precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall
have any liability to any person or entity with respect to any loss or damage caused or alleged to
be caused directly or indirectly by the information contained in this work.
The source code for this book is available to readers at www.apress.com.
v
Contents
Contents at a Glance .......................................................................................... iv
About the Author ............................................................................................... xii
About the Technical Reviewer ......................................................................... xiii
Acknowledgments ............................................................................................ xiv
Introduction ....................................................................................................... xv
■
Chapter 1: Android, the New Kid on the Block ................................................ 1
A Brief History of Android ....................................................................................................................................... 2
Fragmentation ................................................................................................ ......................................................... 3
The Role of Google ................................................................................................................................
.................. 3
The Android Open Source Project ...................................................................................................................... 3
The Android Market ................................................................................................................................
........... 4
Challenges, Device Seeding, and Google I/O
..................................................................................................... 6
Android’s Features and Architecture ................................................................................................
...................... 7
The Kernel .......................................................................................................................................................... 8
The Runtime and Dalvik ................................................................................................................................
..... 8
System Libraries ................................................................................................................................
................ 9
The Application Framework .............................................................................................................................
10
The Software Development Kit .............................................................................................................................
11
The Developer Community ................................................................................................................................
.... 12
Devices, Devices, Devices! ................................................................................................................................... 12
Hardware ................................................................................................................................
......................... 13
First Gen, Second Gen, Next Gen ................................................................................................
..................... 14
Mobile Gaming Is Different ................................................................................................................................
... 20
A Gaming Machine in Every Pocket ................................................................................................
................. 20
Always Connected ................................................................................................................................
........... 21
Casual and Hardcore ................................................................................................................................
........ 22
Big Market, Small Developers ..........................................................................................................................
22
Summary .............................................................................................................................................................. 23
■
Chapter 2: First Steps with the Android SDK ................................................. 25
Setting Up the Development Environment ............................................................................................................ 25
Setting Up the JDK ................................................................................................................................
........... 26
■ CONTENTS
vi
Setting Up the Android SDK ............................................................................................................................. 26
Installing Eclipse ................................................................................................................................
.............. 28
Installing the ADT Eclipse Plug-In ................................................................................................
.................... 28
A Quick Tour of Eclipse ................................................................................................................................
.... 30
Hello World, Android Style ................................................................................................................................
.... 32
Creating the Project ................................................................................................................................
......... 32
Exploring the Project ................................................................................................................................
........ 33
Writing the Application Code ........................................................................................................................... 35
Running and Debugging Android Applications ................................................................................................
...... 38
Connecting a Device ................................................................................................................................ ........ 38
Creating an Android Virtual Device ................................................................................................
.................. 38
Running an Application ................................................................................................................................
.... 39
Debugging an Application ................................................................................................................................
42
LogCat and DDMS ................................................................................................................................
............ 46
Using ADB ................................................................................................................................
........................ 48
Summary .............................................................................................................................................................. 49
■
Chapter 3: Game Development 101 ............................................................... 51
Genres: To Each One’s Taste ................................................................................................................................ 51
Causal Games ................................................................................................................................
.................. 52
Puzzle Games ................................................................................................................................
................... 54
Action and Arcade Games ................................................................................................................................
56
Tower-Defense Games ................................................................................................................................
.... 59
Innovation ................................................................................................................................
........................ 60
Game Design: The Pen Is Mightier Than the Code ................................................................................................
60
Core Game Mechanics ................................................................................................................................
..... 61
A Story and an Art Style ................................................................................................................................
... 63
Screens and Transitions ................................................................................................................................
.. 64
Code: The Nitty-Gritty Details ................................................................................................................................
70
Application and Window Managem
ent ............................................................................................................ 71
Input ................................................................................................................................................................. 72
File I/O ................................................................................................................................
.............................. 75
Audio ................................................................................................................................
................................ 76
Graphics ................................................................................................................................
........................... 80
The Game Framework ................................................................................................................................
...... 94
Summary ............................................................................................................................................................ 101
■
Chapter 4: Android for Game Developers .................................................... 103
Defining an Android Application: The Manifest File ............................................................................................ 104
The <manifest> Element ...............................................................................................................................
105
The <application> Element ...........................................................................................................................
105
The <activity> Element ................................................................................................................................. 107
The <uses-permission> Element .................................................................................................................. 109
The <uses-feature> Element .........................................................................................................................
110
The <uses-sdk> Element ..............................................................................................................................
112
Android Game Project Setup in Ten Easy Steps .............................................................................................
112
Defining the Icon of Your Game ..................................................................................................................... 114
Android API Basics ................................................................................................................................
.............. 116
Creating a Test Project .................................................................................................................................. 116
■ CONTENTS
vii
The Activity Life Cycle . .................................................................................................................................... 120
Input Device Handling . .................................................................................................................................... 127
File Handling .................................................................................................................................................... 144
Audio Programming . ....................................................................................................................................... 150
Playing Sound Effects . .................................................................................................................................... 150
Streaming Music . ............................................................................................................................................ 154
Basic Graphics Programming . ........................................................................................................................ 158
Best Practices .
...................................................................................................................................................... 182
Summary .............................................................................................................................................................. 183
■
Chapter 5: An Android Game Development Framework .............................. 185
Plan of Attack . ....................................................................................................................................................... 185
The AndroidFileIO Class . ...................................................................................................................................... 186
AndroidAudio, AndroidSound, and AndroidMusic: Crash, Bang, Boom! .............................................................. 187
AndroidInput and AccelerometerHand
ler . ............................................................................................................ 192
AccelerometerHandler: Which Side Is
Up? ..................................................................................................... 193
The Pool Class: Because Reuse is Good fo
r You! ............................................................................................ 194
KeyboardHandler: Up, Up, Down, Down, Left, Right . .
. ................................................................................. 196
Touch Handlers ................................................................................................................................................ 200
AndroidInput: The Great Coordinator . ............................................................................................................. 207
AndroidGraphics and AndroidPixmap: Double Rainbow
...................................................................................... 209
Handling Different Screen Sizes and Resolu
tions ........................................................................................... 209
AndroidPixmap: Pixels for the People
. ............................................................................................................ 215
AndroidGraphics: Serving Our Drawing Needs . .............................................................................................. 216
AndroidFastRenderView: Loop, Strech, Loop, Stretch .
................................................................................... 220
AndroidGame: Tying Everything Togeth
er . ........................................................................................................... 223
Summary .............................................................................................................................................................. 227
■
Chapter 6: Mr. Nom Invades Android .......................................................... 229
Creating the Assets ............................................................................................................................................... 229
Setting Up the Project .
......................................................................................................................................... 232
MrNomGame: The Main Activi
ty . ......................................................................................................................... 232
Assets: A Convenient Asset Stor
e . .................................................................................................................. 233
Settings: Keeping Track of User
Choices and High Scores ............................................................................. 234
LoadingScreen: Fetching the Assets from
Disk .............................................................................................. 236
The Main Menu Scree
n . ....................................................................................................................................... 237
The HelpScreen Class(es) . ................................................................................................................................... 241
The High-Scores Screen . ..................................................................................................................................... 243
Rendering Numbers: An Excursion . ................................................................................................................ 243
Implementing the Screen .
............................................................................................................................... 245
Abstracting… .
...................................................................................................................................................... 247
Abstracting the World of Mr. Nom
: Model, View, Controller ........................................................................... 248
The GameScreen Class . .................................................................................................................................. 259
Summary .............................................................................................................................................................. 267
■
Chapter 7: OpenGL ES: A Gentle Introduction .............................................. 269
What Is OpenGL ES and Why Should I Care? . ...................................................................................................... 269
The Programming Model: An Analogy . ............................................................................................................ 270
Projections ....................................................................................................................................................... 272
Normalized Device Space and the Viewpo
rt . .................................................................................................. 275
剩余672页未读,继续阅读
rogerofyan
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页