Android Game Programming For Dummies - Derek James - E-Book

Android Game Programming For Dummies E-Book

Derek James

0,0
23,99 €

oder
-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Learn how to create great games for Android phones Android phones are rapidly gaining market share, nudging theiPhone out of the top spot. Games are the most frequentlydownloaded apps in the Android market, and users are willing to payfor them. Game programming can be challenging, but thisstep-by-step guide explains the process in easily understood terms.A companion Web site offers all the programming examples fordownload. * Presents tricky game programming topics--animation, batteryconservation, touch screen input, and adaptive interface issues--inthe straightforward, easy-to-follow For Dummies fashion * Explains how to avoid pitfalls and create fun games based onbest programming practices for mobile devices * A companion web site includes all programming examples If you have some programming knowledge, Android GameProgramming For Dummies will have you creating cool games forthe Android platform quickly and easily.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 323

Veröffentlichungsjahr: 2012

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Android™ Game Programming For Dummies®

Visit www.dummies.com/cheatsheet/androidgameprogramming to view this book's cheat sheet.

Table of Contents

Introduction
Why You Need This Book
Conventions Used in This Book
Technical Considerations
How This Book Is Organized
Part I: Adopting the Android Gaming Mindset
Part II: Starting to Program
Part III: Making Your First Game: Crazy Eights
Part IV: Moving On to Your Second Game: Whack-a-Mole
Part V: Managing Your Game in the Market
Part VI: The Part of Tens
Icons Used in This Book
Where to Go from Here
Part I: Adopting the Android Gaming Mindset
Chapter 1: Getting to Know Android Gaming
Seeing the Potential of the Android Platform
Where Android came from
And where it’s going
What You Must Know about the Mobile Gaming Industry
Handhelds and smartphones
iOS or Android
How Android Is Suited to Mobile Gaming
Growth
Freedom
Potential
Thinking Through Your Game Project
Designing first
Following a structured development process
Deciding on distribution
Knowing What Tools You Need
Capitalizing on Your Game
The tried-and-true approaches
Chapter 2: Designing Your Game
Deciding What Kind of Game to Make
Genre
Number of players
Thinking about how and when people will play your game
Identifying Your Target Audience
The Android user base
Casting a wide net or finding a niche
Targeting Devices
Firmware
Hardware
Designing the interface and controls
Finding and/or creating resources (graphics and sound)
Chapter 3: Setting Up Your Development Environment
Starting at the Beginning
Downloading and Installing Eclipse
Installing the Software
Installing the SDK
Installing the ADT
Connecting Eclipse to the SDK
The Android Virtual Device (AVD) Manager
Creating a virtual device
Launching a virtual device
Creating an Android Project
Running an Android App
Manual launch control
Starting apps
Part II: Starting to Program
Chapter 4: Dissecting an Android App
Creating a New Project
Taking the Bird’s Eye View of a Project
Editing the Manifest
Naming and versioning your game
Targeting versions
Declaring activities
Setting permissions
Targeting different screen sizes
Organizing Resources
Drawables
Layouts
Strings
Styles
Themes
Sounds
Organizing the Source Directory
Understanding Activities
The lifecycle of an activity
Using Views
Differences between View and SurfaceView
Instantiating a custom view
Drawing in a view
Handling input
Part III: Making Your First Game: Crazy Eights
Chapter 5: Creating a Simple Title Screen
Creating a Custom View
Loading the Title Graphic
Drawing the Title Graphic
Handling Screen Orientation
Controlling Screen Timeout
Making the Game Full-Screen
Adding buttons
Handling Button States
Launching the Play Screen
Intents
Bundles
Chapter 6: Creating a Basic Play Screen
Displaying Cards
Loading the card images
Dealing the cards
Displaying the game state
Taking Your Turn
Handling turns
Picking up cards
Playing cards
Showing dialog boxes (and toasts)
Taking cards from the draw pile
Advancing play
Chapter 7: Finishing Your First Game
Ending Hands and Games
Ending a hand
Ending a game
Wrapping Up the Game
Coding the opponent AI
Making your own launcher icon
Part IV: Moving On to Your Second Game: Whack-a-Mole
Chapter 8: Creating a Complex Title Screen
Using SurfaceView
Adding an Options Menu
Toggling the Sound Option
Chapter 9: Creating an Animated Play Screen
Handling Images for the Play Screen
Making Simple Animations
Handling User Interaction
Loading and Playing Sounds
Handling End of Game
Chapter 10: Storing and Retrieving Game Information
Using Shared Preferences for Data Storage
Using XML for Data Storage
Using a SQLite Database for Data Storage
Part V: Managing Your Game in the Market
Chapter 11: Making Money with Your Game
Knowing Your Competition
Monetization Models
Free
Paid
Free-to-Paid
Ad-based
In-app Purchases
Alternatives to Google Play
Chapter 12: Publishing and Updating Your Game
Creating a developer account for Google Play
Generating a Key with Keytool
Exporting a Signed Application
Uploading Your Game to Google Play
Uploading the APK
Adding product details
Supporting and Updating Your Game After Publication
Part VI: The Part of Tens
Chapter 13: Ten Open-Source Game Projects
Lunar Lander
Replica Island
Alien Blood Bath
OpenSudoku
Lexic
Newton’s Cradle
Vector Pinball
asqare
tiltmazes
GL ES Quake
Chapter 14: Ten Game Engines and Tools
libgdx
AndEngine
Unity
OpenFeint
Flurry
Audacity
sfxr
GIMP
Inkscape
AdWhirl
Chapter 15: Ten More Places to Distribute Your Game
Amazon
Handango
Opera Mobile App Store
GetJar
SlideME
Appoke
AppBrain
AndroLib
Your Website
BitTorrent Sites
Chapter 16: Ten Websites for Android Game Developers
Stack Overflow
Android Developer
anddev.org
Android Developers Blog
Appolicious
Android Tapp
Phandroid
xda developers
Droid Gamers
Android and Me
Glossary
Cheat Sheet

Android™ Game Programming For Dummies®

by Derek James

Android™ Game Programming For Dummies®

Published byJohn Wiley & Sons, Inc.111 River StreetHoboken, NJ 07030-5774www.wiley.com

Copyright © 2013 by John Wiley & Sons, Inc., Hoboken, New Jersey

Published by John Wiley & Sons, Inc., Hoboken, New Jersey

Published simultaneously in Canada

No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions.

Trademarks: Wiley, the Wiley logo, For Dummies, the Dummies Man logo, A Reference for the Rest of Us!, The Dummies Way, Dummies Daily, The Fun and Easy Way, Dummies.com, Making Everything Easier, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates in the United States and other countries, and may not be used without written permission. Android is a trademark of Google Inc. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc. is not associated with any product or vendor mentioned in this book.

Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Website is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Website may provide or recommendations it may make. Further, readers should be aware that Internet Websites listed in this work may have changed or disappeared between when this work was written and when it is read. FULFILLMENT OF EACH COUPON OFFER IS THE SOLE RESPONSIBILITY OF THE OFFEROR.

For general information on our other products and services, please contact our Customer Care Department within the U.S. at 877-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002.

For technical support, please visit www.wiley.com/techsupport.

Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with standard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at http://booksupport.wiley.com. For more information about Wiley products, visit www.wiley.com.

Library of Congress Control Number: 2012950501

ISBN 978-1-118-02774-5 (pbk); 978-1-118-23599-7 (ebk); ISBN 978-1-118-26083-8 (ebk); ISBN 978-1-118-22218-8 (ebk)

Manufactured in the United States of America

10 9 8 7 6 5 4 3 2 1

About the Author

Derek James is the founder and owner of Polyclef Software, one of the most successful Android indie game developers on Google Play. His apps and games have garnered over 1 million combined downloads, with multiple games receiving four-star or better ratings and holding top-ranking positions in their categories for many months. He was an early adopter of the Android platform and has been developing Android apps and games since the first device was released. He lives in Lafayette, Louisiana. You can follow Derek on Polyclef’s Twitter feed (@polyclefapps), his blog (http://polyclefsoftware.blogspot.com), and his website (polyclefsoftware.com).

Dedication

To Jenna, who was there by my side throughout the writing of this book.

Author’s Acknowledgments

Thanks to Acquisitions Editor Kyle Looper for contacting me to work on this book. I’m grateful for the opportunity.

Thanks for Project Editor Pat O’Brien for all the valuable and timely feedback in helping get this book put together.

Jeremy Breaux provided invaluable feedback as technical editor, helping to make sure that the code and examples worked well and were clear.

Finally, thanks to Laurie, as well as my friends and family for being supportive throughout the writing process.

Publisher’s Acknowledgments

We’re proud of this book; please send us your comments at http://dummies.custhelp.com. For other comments, please contact our Customer Care Department within the U.S. at 877-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002.

Some of the people who helped bring this book to market include the following:

Acquisitions, Editorial, and Vertical Websites

Project Editor: Pat O’Brien

Acquisitions Editor: Kyle Looper

Copy Editor: Barry Childs-Helton

Technical Editor: Jeremy Breaux

Editorial Manager: Kevin Kirschner

Editorial Assistant: Leslie Saxman

Sr. Editorial Assistant: Cherie Case

Cover Photo: © iStockphoto.com / Cary Westfall

Cartoons: Rich Tennant (www.the5thwave.com)

Composition Services

Project Coordinator: Katherine Crocker

Layout and Graphics: Carrie A. Cesavice, Joyce Haughey, Christin Swinford

Proofreaders: Melissa Cossell, Shannon Ramsey

Indexer: BIM Indexing & Proofreading Services

Publishing and Editorial for Technology Dummies

Richard Swadley, Vice President and Executive Group Publisher

Andy Cummings, Vice President and Publisher

Mary Bednarek, Executive Acquisitions Director

Mary C. Corder, Editorial Director

Publishing for Consumer Dummies

Kathleen Nebenhaus, Vice President and Executive Publisher

Composition Services

Debbie Stailey, Director of Composition Services

Introduction

There’s something special about games. The best games, the ones we remember, don’t just relieve our boredom from time to time. They teach us new things, stretch our brains, or make us feel happy, excited, and sometimes angry! Social games can even bring us closer to our friends and family. We all have games that we think of fondly, that added something to our lives. Now, with the advent of smartphones, we can carry that experience around in our pockets and purses.

I still remember when my parents hooked up our first video game, Pong, to the family television. At the time that luminescent “ball” traversing the blurry screen was the coolest thing I’d ever seen. I’ve played a lot of games on a lot of platforms in the intervening years, but when my friend Philip gifted me with the first Android phone, the G1, I was skeptical that it would make a very good gaming platform. Who wants to play games by staring at a tiny screen on a device whose primary function is to make phone calls? Then again, the iPhone had by that time already proven that people were not only willing to play games on their smartphones, they were absolutely ravenous for games on their smartphones.

When the Android market launched, it took a little while to get some traction. I developed and published some of the first games on the market, when not many other developers were flocking to the platform. The G1 was a clunky, first-generation device, they said. It’ll never compete with the iPhone, they said. Open platforms are never good for gaming, they said. Well, I was able to make enough games that generated enough income to let me develop for Android full-time. And the platform has come a long way in the meantime; now Google doesn’t have a problem attracting game developers.

When I was approached to write this book, I jumped at the chance to write about a subject that blends my two passions of gaming and programming. I’m guessing you share those passions as well, and want to make cool, compelling games. I’m going to help you make that happen.

Why You Need This Book

Obviously you want to make games for Android, but you may not know where to get started. You may not even have any programming experience — if you do, great! — but I don’t make too many assumptions about your level of experience. By default, Android apps are written in Java. All the examples in this book are also in Java, so it’s helpful, but not necessary, to have some working knowledge of Java. However, even someone with little or no experience should be able to work through this book.

By the end, you’ll have a good understanding of Android, two complete, working and playable games, and a solid foundation for developing and publishing your own games. Along the way, I also talk a bit about how you might get more downloads and actually make money from your games. If any or all of that interests you, this book is a great place to start.

Conventions Used in This Book

Code examples are all in the Java programming language. Android also uses XML files to define layouts and preferences in projects. I use a monospaced font to show examples of the content that lurks in these types of files. The idea is to set the examples apart from other text; they look like this:

System.out.println(“Hello”);

Java and XML are case-sensitive (it matters whether letters are capitalized), so be sure to capitalize letters in any code example from the book exactly as you see them. If you don’t, you’ll see compile errors in Eclipse.

URLs for websites will also appear in monospaced font

http://www.google.com

If you are ever confused about the contents of a given file in any of the projects discussed in this book, you can always refer to the actual source files here:

www.dummies.com/go/androidgameprogramming

Technical Considerations

To develop games for Android, you need a PC running a version of either Linus, Windows, or Mac OS that meets the requirements for both the Android SDK and the Java Development Kit (JDK). Both the SDK and JDK are freely available from their respective websites, where you can find more detail about specific system requirements:

http://developer.android.com/sdk

http://www.oracle.com/technetwork/java/javase/downloads/index.html

Android also uses the Eclipse IDE (integrated development environment), which we will be using throughout this book. Installation of all this software is covered in Chapter 3.

As I stated earlier, a working knowledge of Java and XML are helpful, but not necessary. If you’re familiar with any high-level language and development environment, you should be fine. If not, you should still be able to work through the examples and put together workable games, but you’ll likely have a bit more of a tussle.

If you’re interested in developing for Android, you probably have an Android device, but you don’t necessarily need one. The Android SDK provides an emulator which lets you configure virtual devices to test your games without the actual hardware.

But testing playability without actual devices is not advised. Especially if you’re designing for multiple form factors, such as both phones and tablets, you’ll probably want to invest in at least a couple of test devices.

How This Book Is Organized

Android Game Programming ForDummies is divided into six parts. The following section describes the contents of each part.

Part I: Adopting the Android Gaming Mindset

Part I provides you with a history of Android and mobile gaming to this point in time. I contrast Android game development with other platforms and discuss its pros and cons. This part also helps you think through all the necessary decisions before you begin to program, including the basics of designing a mobile game for Android.

Part II: Starting to Program

Part II walks you through setting up your development environment and installing all the necessary frameworks and tools for building Android games. I show you how to create a simple Android project and run the resulting app on both virtual and real devices. I then walk you through the guts of an Android project to get a closer look at what all the pieces are and how they all fit together to make a game.

Part III: Making Your First Game: Crazy Eights

Part III involves making your first game, the two-player card game Crazy Eights. You create a title screen, load and display graphics, and implement UI elements such as buttons. You implement all the elements for a card game, including such tasks as loading, shuffling, and dealing a virtual deck of cards. You implement all the logic for playing cards and taking turns, and also conjure up a computer opponent to play against. By the end of this part, you’ll have a complete, playable card game for Android.

Part IV: Moving On to Your Second Game: Whack-a-Mole

Part IV shows you how to make a second complete game, Whack-a-Mole. I use a different approach than our first game that’s slightly more complex, but provides the additional rendering speed we need for real-time arcade games. I cover how to generate simple animations and how to load and play sounds in response to events in the game. I also show you how to store and retrieve data, allowing you to manage game states between sessions. By the end of this part, you’ll have a second complete playable game.

Part V: Managing Your Game in the Market

Part V discusses how to make money from your game, if that interests you. I also discuss the nuts and bolts of exporting and digitally signing your game for upload to Google Play. I walk you through the process of creating an uploadable application file, but also all the promotional resources you’ll need for the market listing. I then show you how to upload your game to the market and update it when it’s there.

Part VI: The Part of Tens

Part VI provides you with some handy resources to help you develop your own games while working through this book and moving beyond it. I discuss some intriguing open-source game projects that cover genres and approaches that the two sample games here don’t cover — such as side-scrolling platformers and word games. Then I point you to game engines you can leverage to save you lots of time, and point out some features like physics engines that handle chores like gravity and movement and would take months to implement otherwise. I also talk about free tools to help you create your own graphics and sound resources, as well as frameworks to help you promote and monetize your game.

Icons Used in This Book

This icon indicates useful information you should pay attention to.

This icon represents important overriding concepts that frame all the content in a particular section.

This icon indicates information that dives a bit deeper into the technical aspects of a particular subject. Usually it’s not essential to your understanding of the associated material, but is provided to give you a better handle on the topic.

This icon points out potential problems you might encounter when you’re dealing with a particular aspect of development. Pay particular attention to these and try to avoid these pitfalls when possible.

These links connect you to valuable internet resources.

Where to Go from Here

Are you ready to start developing games for Android? I hope you enjoy the process as much as I enjoyed putting this book together for you. I tried my best to make the subject informative and entertaining, but if you have any additional questions, you can contact me via e-mail at [email protected]. If there are updates, they’ll be posted at

www.dummies.com/go/androidgameprogrammingfordummies

Part I

Adopting the Android Gaming Mindset

In this part . . .

Part I gets you ready to build amazing games by giving you the background you need to understand Android as a gaming platform — and then by walking you through all the necessary steps for designing your game. I discuss the history of Android and mobile gaming, then I talk about all the things you need to consider before firing up your computer to start coding.

Chapter 1

Getting to Know Android Gaming

In This Chapter

Learning the background of Android

Approaching Android as a gaming platform

Planning your first game

You love games and now want to make some of your own, specifically for smartphones and tablets. You’re in luck! These are exciting times for the mobile game industry. Mobile device adoption is exploding, and mobile games are the hottest segment of mobile applications.

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!