You are previewing LibGDX Game Development By Example.
O'Reilly logo
LibGDX Game Development By Example

Book Description

Learn how to create your very own game using the libGDX cross-platform framework

About This Book

  • Learn the core features of libGDX to develop your own exciting games

  • Explore game development concepts through example projects

  • Target games for major app stores quickly and easily with libGDX's cross-platform functionality

  • Who This Book Is For

    This book is intended for those who wish to learn the concepts of game development using libGDX. An understanding of Java and other programming languages would definitely be helpful, although it is not a must.

    What You Will Learn

  • Create and configure a libGDX project to get started with making games

  • Get to grips with a simple game loop that will drive your games

  • Manage game assets to reduce code duplication and speed up development

  • Pack game assets together into single assets to increase your game’s performance

  • Display textures on the screen and manipulate them with play input

  • Play various types of sounds that a game can generate

  • Design and modify a game user interface with libGDX’s built-in tools

  • Develop a game that will run across various platforms

  • In Detail

    LibGDX is a cross-platform game development framework in Java that makes game programming easier and fun to do. It currently supports Windows, Linux, Mac OS X, Android, and HTML5.

    With a vast feature set on offer, there isn't a game that can’t be made using libGDX. It allows you to write your code once and deploy it to multiple platforms without modification. With cross-platform delivery at its heart, a game can be made to target the major markets quickly and cost effectively.

    This book starts with a simple game through which the game update cycle is explained, including loading textures onto your screen, moving them around, and responding to input. From there you’ll move on to more advanced concepts such as creating a formal game structure with a menu screen, adding a game screen and loading screen, sprite sheets, and animations. You’ll explore how to introduce a font to optimize text, and with the help of a game that you’ll create, you’ll familiarise yourself with the 2D tile map API to create worlds that scroll as the characters move.

    In the final sample game of the book, you’ll implement a basic version of an Angry Birds clone, which will allow you to use the physic library box2D that libGDX provides access to. An overview of exporting games to different platforms is then provided.

    Finally, you will discover how to integrate third-party services into games and take a sneak peak at the Social Media API to get a basic understanding of how it fits into the libGDX ecosystem.

    Style and approach

    With this book you’ll learn game development with libGDX through example game projects. You’ll finish the book with a thorough understanding of libGDX game development, along with completed games that you’ll have built yourself.

    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 If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.

    Table of Contents

    1. LibGDX Game Development By Example
      1. Table of Contents
      2. LibGDX Game Development By Example
      3. Credits
      4. About the Author
      5. About the Reviewers
        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. Getting to Know LibGDX
        1. Introducing LibGDX
        2. Setting up LibGDX
        3. Creating a project
          1. What is Gradle?
        4. Importing a project
        5. Summary
      9. 2. Let's Get These Snakes Out of This Book!
        1. Why Snake?
        2. Game update cycle
          1. Texture rendering
            1. The batch class
            2. The texture class
            3. The dispose() method
        3. Introducing Sammy the snake
          1. Giving the snake a face
        4. Moving Sammy the snake
          1. Controlling Sammy with event polling
        5. Adding the apple
        6. Increasing the length of the snake
        7. Summary
      10. 3. Making That Snake Slick
        1. Introducing the ShapeRenderer class
          1. Adding the ShapeRenderer class
          2. Drawing with the ShapeRenderer class
          3. Final thoughts on the ShapeRenderer class
        2. More on collisions
          1. Stopping the doubleback
          2. Colliding with the body
        3. The state of the game
          1. Adding a state
          2. Player feedback
          3. Restart your engines!
        4. High scores
        5. Handling different screen sizes
          1. Introducing the Viewport
          2. Using the Viewport
        6. Summary
      11. 4. What the Flap Is the Hype About?
        1. Why Flappy Bird?
        2. The project setup
          1. Setting up the GameScreen class
        3. Creating Flappee Bee
          1. Flappee Bee
          2. Flapping Flappee
          3. Flower power obstacles
        4. Collisions
          1. Scoring
        5. Adding textures and animations
        6. GUI creation with Scene2D
          1. The Stage class
          2. The Actor class
        7. The Start screen and disposal
          1. The dispose() method
        8. Summary
      12. 5. Making Your Bird More Flightworthy
        1. Let's load up them assets!
          1. Implementing the AssetManager parameter
          2. Loading the loading screen!
        2. Packing textures
          1. Measuring the impact
          2. The GDX-tools TexturePacker
          3. Using the texture atlas
        3. I need a Hiero!
          1. What is Hiero?
        4. Summary
      13. 6. Onto the Next Platform...Game
        1. Why and what is a platformer?
          1. Introducing Pete the platformer
        2. Game reuse
        3. Tile maps – mapping all over the world!
          1. Introducing Tiled
          2. Creating a new map
          3. The LibGDX Tile Map API
        4. Introducing Pete
          1. Adding our character
          2. Making Pete jump!
          3. Adding our artwork
        5. Collision detection
        6. Adding a collectable
        7. Summary
      14. 7. Extending the Platform
        1. Increasing the level
          1. Resizing the Map
          2. Allowing Pete to leave the screen
          3. The camera sees it all
        2. Let's make some noise
          1. Sound effects
          2. Music
          3. If Pete jumps in the game, does anyone hear him?
        3. Summary
      15. 8. Why Are All the Birds Angry?
        1. The what, why, and how of Angry Birds
          1. Why?
          2. How?
        2. Setting up LibGDX with Box2D
          1. Code reuse
          2. Box2D with LibGDX
            1. Box2D concepts
              1. Shape
              2. Rigid body
              3. Fixture
              4. Constraint
              5. The contact constraint
              6. Joint
              7. The joint limit
              8. The joint motor
              9. World
              10. Solver
              11. Units
          3. Creating a world!
        3. Nutty Birds
          1. Let's get tiling!
            1. The groundwork
            2. Adding objects
            3. Importing the tile map
            4. Importing the object layer
            5. Importing the naughty ones!
            6. Fire at will!
            7. Take Aim! Fire!
            8. Time for an art attack!
            9. Ladies and gentleman – the main event!
        4. Summary
      16. 9. Even Angrier Birds!
        1. The how, what, and why of object pools
          1. Object pools with LibGDX
        2. Hey, look at all these acorns!
          1. Pooling the acorns
          2. Freeing the acorns!
        3. Summary
      17. 10. Exporting Our Games to the Platforms
        1. Using all the platforms
        2. Looking closer – Android
          1. Launching the emulator from an IDE
          2. Launching the emulator from the command line
          3. Hang on, how does it work?
          4. Release the Kraken!
        3. Looking closer – iOS
        4. Looking closer – HTML
          1. Getting ready to launch
        5. Summary
      18. 11. Third-party Services
        1. How to use platform-dependent libraries
          1. The nice way – via Maven
          2. An alternative to Maven – A project/JAR file
        2. Keeping it cross-platform friendly
          1. FriendFace for Android
          2. A potential trap! (Android)
        3. Summary
      19. Index