You are previewing Mastering Android Game Development.
O'Reilly logo
Mastering Android Game Development

Book Description

Master game development with the Android SDK to develop highly interactive and amazing games

In Detail

Gaming has historically been a strong driver of technology, whether we're talking about hardware or software performance, the variety of input methods, or graphics support, and the Android game platform is no different. Android is a mature, yet still growing, platform that many game developers have embraced as it provides tools, APIs, and services to help bootstrap Android projects and ensure their success, many of which are specially designed to help game developers.

This book is a progressive, hands-on guide to developing highly interactive and complex Android games from scratch. You will learn all the aspects of developing a game using a space shooter game as the example that will evolve with you through the chapters. You will learn all about frame-by-frame animations and resource animations. You will also create beautiful and responsive menus and dialogs and explore the different options for playing sound effects and music in Android.

You will then learn the basics of creating a particle system and how to use the Leonids library. Finally, we will configure and use Google Play Services on the developer console and port our game to the big screen.

What You Will Learn

  • Understand the internals of a game engine and the reasoning behind each of the components

  • Decide when to use each of the different ways of drawing on Android

  • Handle user inputs, from virtual joysticks to gamepads

  • Implement collision detection using different techniques and discover how to optimize it for complex games

  • Use animations and particle systems to provide a rich experience

  • Create beautiful, responsive, and reusable UIs by taking advantage of the Android SDK

  • Integrate Google Play Services to provide achievements and leaderboards to the players

  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

    Table of Contents

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