Learning LibGDX Game Development - Second Edition

Book description

Wield the power of the LibGDX framework to create a cross-platform game

In Detail

LibGDX is a multiplatform game development framework, and is one of the most popular frameworks for building games, providing a comprehensive set of development capabilities and features to use and incorporate into games.

This book starts off by introducing you to LibGDX and how to use its project setup tool to build an application that can support multiple platforms, before gradually moving on to configuring your game. Then, you will learn to organize resources, create a scene, actors, and a menu system. You will also enhance the visual appearance of your game and manage its transitions, along with music and sound effects. You will then move on to cover the advanced programming techniques and create and manage different kinds of animations.

Finally, you will be introduced to the basics of 3D programming and the 3D physics engine. By the end of this book, you will be able to start developing your very own cross-platform games using the LibGDX framework.

What You Will Learn

  • Set up a cross-platform project using Gradle and test the base code required for game building
  • Speed up your overall productivity with the stunning JVM Code Hot Swapping feature
  • Use Scene2D to create and organize complex menu structures
  • Automate the creation of texture atlases using TexturePacker
  • Manage and play audio files and add special effects to your game to improve its look and feel
  • Learn 2D physics simulation using Box2D
  • Understand more about 3D programming using the new LibGDX 3D API
  • Use the LibGDX Bullet wrapper for 3D physics simulation

Table of contents

  1. Learning LibGDX Game Development Second Edition
    1. Table of Contents
    2. Learning LibGDX Game Development Second Edition
    3. Credits
    4. About the Authors
    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. Introduction to LibGDX and Project Setup
      1. Diving into LibGDX
      2. Features of LibGDX 1.2.0
        1. Graphics
        2. Audio
        3. Input handling
        4. File I/O and storage
        5. Math and physics
        6. Utilities
        7. Tools
      3. Getting in touch with the community
      4. Prerequisites to install and configure LibGDX
        1. Java Development Kit
        2. Eclipse – Integrated Development Environment
        3. Downloading LibGDX
        4. Installing Android SDK
        5. Running Eclipse and installing plugins
      5. Creating a new application
        1. Using the old setup tool
        2. Using the Gradle-based setup
      6. gdx-setup versus gdx-setup-ui
      7. Kicking your game to life
      8. Key to success lies in planning
      9. Game project – Canyon Bunny
        1. Description of the game
      10. Summary
    9. 2. Cross-platform Development – Build Once, Deploy Anywhere
      1. The demo application – how the projects work together
      2. LibGDX backends
        1. Lightweight Java Game Library
        2. Android
        3. WebGL
        4. RoboVM (iOS backend)
      3. LibGDX core modules
        1. The application module
          1. Logging
          2. Shutting down gracefully
          3. Persisting data
          4. Querying the Android API level
          5. Querying the platform type
          6. Querying the memory usage
          7. Multithreading
        2. The graphics module
          1. Querying delta time
          2. Querying display size
          3. Querying the frames per second (FPS) counter
        3. The audio module
          1. Sound playback
          2. Music streaming
        4. The input module
          1. Reading the keyboard/touch/mouse input
          2. Reading the accelerometer
          3. Starting and canceling vibrator
          4. Catching Android's soft keys
        5. The files module
          1. Getting an internal file handle
          2. Getting an external file handle
        6. The network module
          1. HTTP requests
          2. Client/server sockets
          3. Opening a URI in a web browser
      4. LibGDX's application life cycle and interface
      5. Starter classes
        1. Running the demo application on a desktop
        2. Running the demo application on Android
        3. Running the demo application in a WebGL-capable web browser
        4. Running the demo application on an iOS device
      6. The demo application – time for code
        1. Inspecting an example code of the demo application
          1. The create() method
          2. The render() method
          3. The dispose() method
        2. Having fun with the debugger and Code Hot Swapping
      7. Summary
    10. 3. Configuring the Game
      1. Setting up the Canyon Bunny project
      2. Using a class diagram for Canyon Bunny
      3. Laying foundations
        1. Implementing the Constants class
        2. Implementing the CanyonBunnyMain class
        3. Implementing the WorldController class
        4. Implementing the WorldRenderer class
      4. Putting it all together
        1. Building the game loop
        2. Adding the test sprites
        3. Adding the game world's debug controls
        4. Adding the CameraHelper class
        5. Adding the camera debug controls using CameraHelper
      5. Summary
    11. 4. Gathering Resources
      1. Setting up a custom Android application icon
      2. Setting up a custom iOS application icon
      3. Creating the texture atlases
      4. Loading and tracking assets
      5. Organizing the assets
      6. Testing the assets
      7. Handling level data
      8. Summary
    12. 5. Making a Scene
      1. Creating game objects
        1. The rock object
        2. The mountains object
        3. The water overlay object
        4. The clouds object
      2. Implementing the level loader
      3. Assembling the game world
      4. Implementing the game GUI
        1. The GUI score
        2. The GUI extra lives
        3. The GUI FPS counter
        4. Rendering the GUI
      5. Summary
    13. 6. Adding the Actors
      1. Implementing the actor game objects
        1. Creating the gold coin object
        2. Creating the feather object
        3. Creating the bunny head object
        4. Updating the rock object
      2. Completing the level loader
      3. Adding the game logic
        1. Adding collision detection
        2. Losing lives, game over, and fixing the camera
        3. Adding the game over text and the feather icon to the GUI
      4. Summary
    14. 7. Menus and Options
      1. Managing multiple screens
      2. Exploring Scene2D UI, TableLayout, and skins
      3. Using LibGDX's scene graph for the menu UI
      4. Building the scene for the menu screen
        1. Adding the background layer
        2. Adding the objects layer
        3. Adding the logos layer
        4. Adding the controls layer
        5. Adding the Options window layer
      5. Building the Options window
        1. Using the game settings
      6. Summary
    15. 8. Special Effects
      1. Creating complex effects with particle systems
      2. Adding a dust particle effect to the player character
      3. Moving the clouds
      4. Smoothing with linear interpolation (Lerp)
        1. Letting the rocks float on the water
      5. Adding parallax scrolling to the mountains in the background
      6. Enhancing the game screen's GUI
        1. Event – player lost a life
        2. Event – score increased
      7. Summary
    16. 9. Screen Transitions
      1. Adding the screen transition capability
        1. Implementing the transition effects
        2. Knowing about interpolation algorithms
        3. Creating a fade transition effect
        4. Creating a slide transition effect
        5. Creating a slice transition effect
      2. Summary
    17. 10. Managing the Music and Sound Effects
      1. Playing back the music and sound effects
        1. Exploring the Sound interface
        2. Exploring the Music interface
      2. Accessing the audio device directly
        1. Exploring the AudioDevice interface
        2. Exploring the AudioRecorder interface
      3. Using sound generators
        1. The sfxr generator
        2. The cfxr generator
        3. The bfxr generator
      4. Adding music and sounds to Canyon Bunny
      5. Summary
    18. 11. Advanced Programming Techniques
      1. Simulating physics with Box2D
        1. Exploring the concepts of Box2D
          1. Understanding the rigid bodies
          2. Choosing the body types
          3. Using shapes
          4. Using fixtures
          5. Simulating physics in the world
        2. Physics body editor
        3. Adding Box2D
          1. Adding Box2D dependency in Gradle
          2. For non-Gradle users
        4. Preparing Canyon Bunny for raining carrots
          1. Adding the new assets
          2. Adding the carrot game object
          3. Adding the goal game object
          4. Extending the level
        5. Letting it rain carrots
      2. Working with shaders in LibGDX
        1. Creating a monochrome filter shader program
        2. Using the monochrome filter shader program in Canyon Bunny
      3. Adding alternative input controls
      4. Summary
    19. 12. Animations
      1. Manipulating actors through actions
        1. Actions for manipulating actors
        2. Controlling the order and time of execution
      2. Animating the menu screen
        1. Animating the gold coins and bunny head actors
        2. Animating the menu buttons and options window
      3. Using sequences of images for animations
        1. Packing animations using TexturePacker
        2. Choosing between animation play modes
      4. Animating the game screen
        1. Defining and preparing new animations
        2. Animating the gold coin game object
        3. Animating the bunny head game object
      5. Summary
    20. 13. Basic 3D Programming
      1. Light sources
      2. Environment and materials
      3. Basic 3D using LibGDX
        1. The project setup
        2. The camera
        3. Model and ModelInstances
        4. The ModelBatch class
        5. The environment
      4. Loading a model
        1. Model formats and the FBX converter
      5. 3D frustum culling
      6. Ray picking
      7. Summary
    21. 14. Bullet Physics
      1. About Bullet Physics
      2. A few basic concepts
        1. Understanding rigid bodies
          1. Static, dynamic, and kinematic rigid bodies
        2. Collision shapes
        3. MotionStates
        4. Simulating physics
      3. Learning Bullet with LibGDX
        1. Setting up a project
        2. Creating a basic 3D scene
        3. Initializing Bullet
        4. Creating a dynamics world
        5. A custom MotionState class
        6. A simple ContactListener class
      4. Adding some rigid bodies
      5. Stepping the world
        1. Ray casting in Bullet
        2. A simple test game
      6. Having fun with shadows
      7. Summary
    22. Index

Product information

  • Title: Learning LibGDX Game Development - Second Edition
  • Author(s): Suryakumar Balakrishnan Nair, Andreas Oehlke
  • Release date: January 2015
  • Publisher(s): Packt Publishing
  • ISBN: 9781783554775