Mastering Android Game Development
eBook - ePub

Mastering Android Game Development

Raul Portales

Share book
  1. 372 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Mastering Android Game Development

Raul Portales

Book details
Book preview
Table of contents
Citations

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Mastering Android Game Development an online PDF/ePUB?
Yes, you can access Mastering Android Game Development by Raul Portales in PDF and/or ePUB format, as well as other popular books in Computer Science & Artificial Intelligence (AI) & Semantics. We have over one million books available in our catalogue for you to explore.

Information

Mastering Android Game Development


Table of Contents

Mastering Android Game Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Setting Up the Project
The right tool for the right game
Do you want to use 3D?
Do you want to use physics?
Do you want to use Java?
Pros of building games with the Android SDK
Cons of building games with the Android SDK
I want the Android SDK!
The project – YASS (Yet Another Space Shooter)
Activities and Fragments
Project setup
Creating the stub project
Cleaning up
Choosing an orientation
Dealing with aspect ratios
Game architecture
GameEngine and GameObjects
Starting a game
Stopping a game
Managing game objects
UpdateThread
DrawThread
User input
Putting everything together
Moving forward with the example
Handling the back key
Honoring the lifecycle
Using as much screen as we can
Before Android 4.4 – almost fullscreen
Android 4.4 and beyond – immersive mode
Putting fullscreen together
Good practices for game developers
Object pools
Avoiding enhanced loop syntax in lists
Precreating objects
Accessing variables directly
Being careful with floating points
Performance myths – avoid interfaces
Summary
2. Managing User Input
The InputController base class
The Player object
Displaying a spaceship
Firing bullets
The Bullet game object
The most basic virtual keypad
Limitations and problems
Creating a virtual joystick
General considerations and improvements
Physical controllers
Handling MotionEvents
Handling KeyEvents
Detecting gamepads
Sensors and InputControllers
Selecting control modes
Summary
3. Into the Draw Thread
Using GameView
The GameView interface
StandardGameView
SurfaceGameView
Updating GameEngine
Updating the game layout
Improving DrawThread
Sprites
Updating the spaceship and bullets
Adding a frames-per-second (fps) counter
Spawning enemies – the GameController
Procedural/random
Deterministic/static
Hybrid approach
Our approach
The asteroids
More on the transformation matrix
Occlusion culling
Parallax backgrounds
Multiple backgrounds
Layers
Summary
4. Collision Detection
Detecting collisions
Who can collide?
Updating GameEngine
Handling collisions
Rectangular bodies
Adding visual feedback
Pros and cons
Circular bodies
Adding visual feedback
Pros and cons
Mixed collision detection
Adding visual feedback
Other options for shapes
Optimization
Spatial partitioning and QuadTree
Duplicated collisions
Summary
5. Particle Systems
General concepts
Particles
ParticleSystem
Initializers
Modifiers
Composite GameObjects and GameEngine
Making good particle systems
One shot
Asteroid explosions
Spaceship explosions
Emitters
Asteroid trails
The spaceship's engine
Summary
6. Sound FX and Music
SoundManager
Sound FX
How to create sound FXs
GameEvents
Using SoundPool
Playing music
Obtaining music
MediaPlayer
Music and Activity life cycle
Enabling and disabling music and sound FX
Updating MainMenuFragment
Updating SoundManager
Disabling system sounds
Summary
7. Menus and Dialogs
Custom fonts
Working with backgrounds
The power of XML drawables
State list drawables
State lists colors
Shape drawables
The GameFragment
Adding a score
Adding lives
Custom dialogs
BaseCustomDialog
Quit dialog
Pause dialog
Game Over dialog
Other dialogs
Designing for multiple screen sizes
Summary
8. The Animation Framework
Updating BaseFragment
AnimationDrawable
Animated sprites
Animating views
XML versus code
Interpolators
View animation
Animating dialogs
Delaying the action in the dialogs to onDismissed
Pulsating buttons
Property animation
ViewPropertyAnimator
Moving a spaceship around
Animating the main menu
Summary
9. Integrating Google Play Services
Setting up the developer console
Setting up the code
Achievements
Architecture
Unlocking achievements
Leaderboards
Opening the Play Games UI
Other features of Google Play services
Events
Quests
Gifts
Saved games
Multiplayer games
Summary
10. To the Big Screen
Project configuration
Testing for Android TV
Declaring a TV Activity
Providing a home screen banner
Declaring it as a game
Declaring Leanback support
Declaring touchscreen capability as not required
Reviewing the manifest
Showing controller instructions
Dealing with overscan
Controller-based navigation
Dialogs and controllers
Beyond this book
Summary
A. API Levels for Android Versions
Index

Mastering Android Game Development

Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: June 2015
Production reference: 1250615
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78355-177-4
www.packtpub.com

Credits

Author
Raul Portales
Reviewers
Sergio Viudes Carbonell
Antonio Hernåndez Niñirola
Commissioning Editor
Nadeem N. Bagban
Acquisition Editor
Harsha Bharwani
Content Development Editor
Arun Nadar
Technical Editor
Ruchi Desai
Copy Editors
Stephen Copestake
Akshata Lobo
Project Coordinator
Nikhil Nair
Proofreader
Safis Editing
Indexer
Monica Ajmera Mehta
Graphics
Abhinash Sahu
Production Coordinator
Conidon Miranda
Cover Work
Conidon Miranda

About the Author

Raul Portales is a software engineer who works as a contract consultant with Platty Soft. He cofounded the game studio The Pill Tree, which ran for a year and produced several titles that were featured by Google Play, including Chalk Ball and SpaceCat.
He has been a Google Developer Expert for Android since the start of 2015, and he loves public speaking. He has presented at several DroidCons and Game Developers conferences, talking about how to survive as an indie game developer.
At the moment, Raul lives in Dublin and you can easily find him collaborating with the local commu...

Table of contents