Beginning Android 4. Games Development. Mario Zechner. Robert Green



Similar documents
Practical Android Projects Lucas Jordan Pieter Greyling

LibGDX játék fejlesztése és publikálása Google Play-en. Vörös Viktor, NNG

Game Development in Android Disgruntled Rats LLC. Sean Godinez Brian Morgan Michael Boldischar

Shader Model 3.0. Ashu Rege. NVIDIA Developer Technology Group

Image Processing and Computer Graphics. Rendering Pipeline. Matthias Teschner. Computer Science Department University of Freiburg

ANDROID INTRODUCTION TO ANDROID

«compl*tc IDIOT'S GUIDE. Android App. Development. by Christopher Froehlich ALPHA. A member of Penguin Group (USA) Inc.

GPU Architecture. Michael Doggett ATI

Introduction to Computer Graphics

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

Lecture 1 Introduction to Android

Programming 3D Applications with HTML5 and WebGL

Workshop on Android and Applications Development

Jordan Jozwiak November 13, 2011

CS 528 Mobile and Ubiquitous Computing Lecture 2: Android Introduction and Setup. Emmanuel Agu

Table of Contents. Adding Build Targets to the SDK 8 The Android Developer Tools (ADT) Plug-in for Eclipse 9

DEVELOPING MOBILE APPLICATIONS USING ANDROID

Beginning Android Programming

1. Introduction to Android

Mobility Introduction Android. Duration 16 Working days Start Date 1 st Oct 2013

Beginning Facebook. Development. Game Apps. Wayne Graham. Apress*

An Introduction to Android

Tutorial on Basic Android Setup

Reminders. Lab opens from today. Many students want to use the extra I/O pins on

Issues in Android on Mobile Platform and Their Resolution

Recent Advances and Future Trends in Graphics Hardware. Michael Doggett Architect November 23, 2005

Beginning BlackBerry 7

Mobile Application Development 2014

An Introduction to Android. Huang Xuguang Database Lab. Inha University

COURSE CONTENT. GETTING STARTED Select Android Version Create RUN Configuration Create Your First Android Activity List of basic sample programs

Android Developer Fundamental 1

Android (Basic + Advance) Application Development

l What is Android? l Getting Started l The Emulator l Hello World l ADB l Text to Speech l Other APIs (camera, bitmap, etc)

Android Development. Lecture AD 0 Android SDK & Development Environment. Università degli Studi di Parma. Mobile Application Development

Board also Supports MicroBridge

The "Eclipse Classic" version is recommended. Otherwise, a Java or RCP version of Eclipse is recommended.

01. Introduction of Android

Graduate presentation for CSCI By Janakiram Vantipalli ( Janakiram.vantipalli@colorado.edu )

TEACHING GRAPHICS PROGRAMMING ON MOBILE DEVICES

Computer Graphics on Mobile Devices VL SS ECTS

ANDROID PROGRAMMING - INTRODUCTION. Roberto Beraldi

Università Degli Studi di Parma. Distributed Systems Group. Android Development. Lecture 1 Android SDK & Development Environment. Marco Picone

Example Connection between USB Host and Android

Introduction to Android

Android and OpenGL. Android Smartphone Programming. Matthias Keil. University of Freiburg

Google Android Syllabus

L20: GPU Architecture and Models

How To Teach Computer Graphics

Introduction to Android

A Short Introduction to Computer Graphics

Android Programming and Security

Gideros Mobile Game Development

Running Android Applications on BlackBerry 10 developer.blackberry.com/android

Android Mobile App Building Tutorial

Fahim Uddin 1. Java SDK

How To Understand The Power Of Unity 3D (Pro) And The Power Behind It (Pro/Pro)

Silverlight for Windows Embedded Graphics and Rendering Pipeline 1

Game Programming with DXFramework

Getting started with Android and App Engine

Development. SriSeshaa Technologies. Table of Contents

Islamic University of Gaza. Faculty of Engineering. Computer Engineering Department. Mobile Computing ECOM Eng. Wafaa Audah.

CS378 -Mobile Computing. Android Overview and Android Development Environment

Mobile Game and App Development the Easy Way

Introduction to Android Development. Jeff Avery CS349, Mar 2013

Specialized Android APP Development Program with Java (SAADPJ) Duration 2 months

Creating and Using Databases for Android Applications

Android Development Tools for Eclipse

Performance Optimization and Debug Tools for mobile games with PlayCanvas

Android Application Development

Java game programming. Game engines. Fayolle Pierre-Alain

Android Development. Marc Mc Loughlin

INTRODUCTION TO RENDERING TECHNIQUES

Examples. Pac-Man, Frogger, Tempest, Joust,

OpenGL Performance Tuning

Introduction to Android: Hello, Android! 26 Mar 2010 CMPT166 Dr. Sean Ho Trinity Western University

Mobile App Design and Development

Android Application Development. Daniel Switkin Senior Software Engineer, Google Inc.

Issues of Hybrid Mobile Application Development with PhoneGap: a Case Study of Insurance Mobile Application

Introduction to GPGPU. Tiziano Diamanti

Технологии Java. Android: Введение. Кузнецов Андрей Николаевич. Санкт-Петербургский Государственный Политехнический Университет

Optimizing Unity Games for Mobile Platforms. Angelo Theodorou Software Engineer Unite 2013, 28 th -30 th August

Bachelor of Games and Virtual Worlds (Programming) Subject and Course Summaries

Blender Notes. Introduction to Digital Modelling and Animation in Design Blender Tutorial - week 9 The Game Engine

Optimizing AAA Games for Mobile Platforms

Android Setup Phase 2

Cisco Cius Development Guide Version 1.0 September 30, 2010

Introduction to NaviGenie SDK Client API for Android

Windows Phone 7 Game Development using XNA

How To Run A Factory I/O On A Microsoft Gpu 2.5 (Sdk) On A Computer Or Microsoft Powerbook 2.3 (Powerpoint) On An Android Computer Or Macbook 2 (Powerstation) On

Praktikum Entwicklung Mediensysteme (für Master)

Basic Android Setup Windows Version

Course Overview. CSCI 480 Computer Graphics Lecture 1. Administrative Issues Modeling Animation Rendering OpenGL Programming [Angel Ch.

Workstation Applications for Windows. NVIDIA MAXtreme User s Guide

Running a Program on an AVD

Mocean Android SDK Developer Guide

Full version is >>> HERE <<<

INTRODUCTION TO ANDROID CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 11 02/15/2011

Transcription:

Beginning Android 4 Games Development Mario Zechner Robert Green

Contents Contents at a Glance About the Authors Acknowledgments Introduction iv xii xiii xiv Chapter 1: Android, the New Kid on the Block... 1 A Brief History of Android 2 Fragmentation 3 The Role of Google 4 The Android Open Source Project 4 The Android Market 4 Challenges, Device Seeding, and Google I/O 5 Android's Features and Architecture 6 The Kernel 7 The Runtime and Dalvik 7 System Libraries 8 The Application Framework 9 The Software Development Kit 10 The Developer Community 11 Devices, Devices, Devices! 12 Hardware 12 The Range of Devices 14 Compatibility Across All Devices 19 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 Setting Up the Android SDK 26 V

CONTEXTS Installing Eclipse 28 Installing the ADT Eclipse Plug-In 28 A Quick Tour of Eclipse 30 Helpful Eclipse Shortcuts 32 Hello World, Android Style 33 Creating the Project 33 Exploring the Project 34 Writing the Application Code 36 Running and Debugging Android Applications 39 Connecting a Device 39 Creating an Android Virtual Device 39 Running an Application 41 Debugging an Application 44 LogCatand DDMS 48 Using ADB 50 Summary 51 Chapter 3: Game Development 101 53 Genres: To Each One's Taste 54 Casual Games 54 Puzzle Games 56 Action and Arcade Games 58 Tower-Defense Games 61 Innovation 62 Game Design: The Pen Is Mightier Than the Code 63 Core Game Mechanics 64 A Story and an Art Style 66 Screens and Transitions 67 Code: The Nitty-Gritty Details 73 Application and Window Management 74 Input 75 File I/O 79 Audio 79 Graphics 84 The Game Framework 97 Summary 105 Chapter 4: Android for Game Developers 107 Defining an Android Application: The Manifest File 108 The <manifest> Element 109 The <application> Element 110 The <activity> Element 111 The <uses-permission> Element, 113 The <uses-feature> Element 114 The <uses-sdk> Element 116 Android Game Project Setup in Ten Easy Steps 117 Market Filters 119 Defining the Icon of Your Game 119 Android API Basics 121 vl

CONTENTS Creating a Test Project 121 The Activity Life Cycle 125 Input Device Handling 132 File Handling 152 Audio Programming 158 Playing Sound Effects 159 Streaming Music 163 Basic Graphics Programming 167 Best Practices 192 Summary 193 Chapter 5: An Android Game Development Framework 195 Plan of Attack 195 The AndroidFilelO Class 196 AndroidAudio, AndroidSound, and AndroidMusic: Crash, Bang, Boom! 197 Androidlnput and AccelerometerHandler 202 AccelerometerHandler: Which Side Is Up? 202 CompassHandler 204 The Pool Class: Because Reuse Is Good for You! 205 KeyboardHandler: Up, Up, Down, Down, Left, Right 207 Touch Handlers 211 Androidlnput: The Great Coordinator 219 AndroidGraphics and AndroidPixmap: Double Rainbow 221 Handling Different Screen Sizes and Resolutions 221 AndroidPixmap: Pixels for the People 226 AndroidGraphics: Serving Our Drawing Needs 227 AndroidFastRenderView: Loop, Stretch, Loop, Stretch 231 AndroidGame: Tying Everything Together 234 Summary 238 Chapter 6: Mr. Norn Invades Android 239 Creating the Assets 239 Setting Up the Project 241 MrNomGame: The Main Activity 242 Assets: A Convenient Asset Store 242 Settings: Keeping Track of User Choices and High Scores 243 LoadingScreen: Fetching the Assets from Disk 246 The Main Menu Screen 247 The HelpScreen Class(es) 251 The High-Scores Screen 253 Rendering Numbers: An Excursion 253 Implementing the Screen 255 Abstracting 257 Abstracting the World of Mr. Norn: Model, View, Controller 258 The GameScreen Class 270 Summary 277 Chapter 7: OpenGL ES: A Gentle Introduction 279 What is OpenGL ES and Why Should I Care? 279 The Programming Model: An Analogy 280 Vii

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 329 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? v Removing Unnecessary State Changes 349 Reducing Texture Size Means Fewer Pixels to be Fetched Reducing Calls to OpenGL ES/JNI Methods The Concept of Binding Vertices InClosing Summary Chapter 8:2D Game Programming Tricks 282 284 284 285 286 287 290 297 298 298 302 306 309 313 313 315 316 317 318 318 318 321 323 324 326 333 334 334 335 336 341 345 345 347 347 351 352 352 356 '. 356 Before We Begin 357 In the Beginning... There Was the Vector, 358 Working with Vectors 359 A Little Trigonometry 361 Implementing a Vector Class 363 357 Vlil

CONTENTS A Simple Usage Example 366 A Little Physics in 2D 371 Newton and Euler, Best Friends Forever 371 Force and Mass 372 Playing Around, Theoretically 373 Playing Around, Practically 374 Collision Detection and Object Representation in 2D 378 Bounding Shapes 379 Constructing Bounding Shapes 381 Game Object Attributes 383 Broad-Phase and Narrow-Phase Collision Detection 384 An Elaborate Example 391 A Camera in 2D 404 The Camera2D Class 407 An Example, 409 Texture Atlas: Because Sharing Is Caring 410 An Example 412 Texture Regions, Sprites, and Batches: Hiding OpenGL ES 416 The TextureRegion Class 417 The SpriteBatcher Class, 418 Sprite Animation 427 The Animation Class 428 An Example 429 Summary 433 Chapter 9: Super Jumper: A 2D OpenGL ES Game. 435 Core Game Mechanics 435 A Backstory and Art Style 436 Screens and Transitions 437 Defining the Game World 438 Creating the Assets 441 The Ul Elements 441 Handling Text with Bitmap Fonts 443 The Game Elements 445 Texture Atlas to the Rescue 447 Music and Sound 448 Implementing Super Jumper 449 The Assets Class 450 The Settings Class 453 The Main Activity 454 The Font Class 456 GLScreen 457 The Main Menu Screen 458 The Help Screens 461 The High-Scores Screen 463 The Simulation Classes 466 The Game Screen 481 The WorldRenderer Class 489 Ix

CONTENTS To Optimize or Not to Optimize 492 Summary 493 Chapter 10: OpenGL ES: Going 3D 495 Before We Begin 495 Vertices in 3D 496 Vertices3: Storing 3D Positions 496 An Example 498 Perspective Projection: The Closer, the Bigger 502 Z-buffer: Bringing Order into Chaos 505 Fixing the Last Example 506 Blending: There's Nothing Behind You 507 Z-buffer Precision and Z-fighting 510 Defining 3D Meshes 511 A Cube: Hello World in 3D 512 An Example 514 Matrices and Transformations Again, 517 The Matrix Stack 518 Hierarchical Systems with the Matrix Stack 520 A Simple Camera System 527 Summary 531 Chapter 11:3D Programming Tricks 533 Before We Begin 533 Vectors in 3D 534 Lighting in OpenGL ES 538 How Lighting Works 538 Light Sources 540 Materials 541 How OpenGL ES Calculates Lighting: Vertex Normals 542 In Practice 542 Some Notes on Lighting in OpenGL ES 556 Mipmapping 557 Simple Cameras 561 The First-Person or Euler Camera 562 A Euler Camera Example 565 A Look-At Camera 571 Loading Models 573 The Wavefront OBJ Format 573 Implementing an OBJ Loader 574 Using the OBJ Loader 579 Some Notes on Loading Models 579 A Little Physics in 3D 580 Collision Detection and Object Representation in 3D 581 Bounding Shapes in 3D 581 Bounding Sphere Overlap Testing 582 Game0bject3D and DynamicGameObject3D 583 Summary 584 X

CONTENTS Chapter 12: Droid Invaders: The Grand Finale 587 Core Game Mechanics 587 A Backstory and Art Style 589 Screens and Transitions 590 Defining the Game World 591 Creating the Assets 593 The Ul Assets 593 The Game Assets 594 Sound and Music 596 Plan of Attack 596 The Assets Class 597 The Settings Class 600 The Main Activity 601 The Main Menu Screen 602 The Settings Screen 604 The Simulation Classes 607 The Shield Class 608 The Shot Class 608 The Ship Class 609 The Invader Class 611 The World Class 614 The GameScreen Class 620 TheWorldRender Class 626 Optimizations 632 Summary 633 Chapter 13: Publishing Your Game... 635 A Word on Testing 635 Becoming a Registered Developer 636 Signing Your Game's APK 637 Putting Your Game on the Market 642 Uploading Assets 643 Product Details 644 Publishing Options 644 Publish! 645 Marketing 645 The Developer Console 645 Summary 646 Chapter 14: What's Next? 647 Getting Social 647 Location Awareness 647 Multiplayer Functionality 648 OpenGL ES 2.0 and More 648 Frameworks and Engines 648 Resources on the Web 650 Closing Words 651 Index 653 xl