LibGDX Game Development By Example
Table of Contents
LibGDX Game Development By Example
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. Getting to Know LibGDX
Introducing LibGDX
Setting up LibGDX
Creating a project
What is Gradle?
Importing a project
Summary
2. Let's Get These Snakes Out of This Book!
Why Snake?
Game update cycle
Texture rendering
The batch class
The texture class
The dispose() method
Introducing Sammy the snake
Giving the snake a face
Moving Sammy the snake
Controlling Sammy with event polling
Adding the apple
Increasing the length of the snake
Summary
3. Making That Snake Slick
Introducing the ShapeRenderer class
Adding the ShapeRenderer class
Drawing with the ShapeRenderer class
Final thoughts on the ShapeRenderer class
More on collisions
Stopping the doubleback
Colliding with the body
The state of the game
Adding a state
Player feedback
Restart your engines!
High scores
Handling different screen sizes
Introducing the Viewport
Using the Viewport
Summary
4. What the Flap Is the Hype About?
Why Flappy Bird?
The project setup
Setting up the GameScreen class
Creating Flappee Bee
Flappee Bee
Flapping Flappee
Flower power obstacles
Collisions
Scoring
Adding textures and animations
GUI creation with Scene2D
The Stage class
The Actor class
The Start screen and disposal
The dispose() method
Summary
5. Making Your Bird More Flightworthy
Let's load up them assets!
Implementing the AssetManager parameter
Loading the loading screen!
Packing textures
Measuring the impact
The GDX-tools TexturePacker
Using the texture atlas
I need a Hiero!
What is Hiero?
Summary
6. Onto the Next Platform...Game
Why and what is a platformer?
Introducing Pete the platformer
Game reuse
Tile maps â mapping all over the world!
Introducing Tiled
Creating a new map
The LibGDX Tile Map API
Introducing Pete
Adding our character
Making Pete jump!
Adding our artwork
Collision detection
Adding a collectable
Summary
7. Extending the Platform
Increasing the level
Resizing the Map
Allowing Pete to leave the screen
The camera sees it all
Let's make some noise
Sound effects
Music
If Pete jumps in the game, does anyone hear him?
Summary
8. Why Are All the Birds Angry?
The what, why, and how of Angry Birds
Why?
How?
Setting up LibGDX with Box2D
Code reuse
Box2D with LibGDX
Box2D concepts
Shape
Rigid body
Fixture
Constraint
The contact constraint
Joint
The joint limit
The joint motor
World
Solver
Units
Creating a world!
Nutty Birds
Let's get tiling!
The groundwork
Adding objects
Importing the tile map
Importing the object layer
Importing the naughty ones!
Fire at will!
Take Aim! Fire!
Time for an art attack!
Ladies and gentleman â the main event!
Summary
9. Even Angrier Birds!
The how, what, and why of object pools
Object pools with LibGDX
Hey, look at all these acorns!
Pooling the acorns
Freeing the acorns!
Summary
10. Exporting Our Games to the Platforms
Using all the platforms
Looking closer â Android
Launching the emulator from an IDE
Launching the emulator from the command line
Hang on, how does it work?
Release the Kraken!
Looking closer â iOS
Looking closer â HTML
Getting ready to launch
Summary
11. Third-party Services
How to use platform-dependent libraries
The nice way â via Maven
An alternative to Maven â A project/JAR file
Keeping it cross-platform friendly
FriendFace for Android
A potential trap! (Android)
Summary
Index
LibGDX Game Development By Example
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: August 2015
Production reference: 1210815
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78528-144-0
www.packtpub.com
Author
James Cook
Reviewers
Pavel Czempin
LĂ©vĂȘque Michel
Sudarshan Shetty
Acquisition Editors
Subho Gupta
James Jones
Content Development Editor
Nikhil Potdukhe
Technical Editor
Abhishek R. Kotian
Copy Editor
Pranjali Chury
Project Coordinator
Mary Alex
Proofreader
Safis Editing
Indexer
Monica Ajmera Mehta
Graphics
Dan Smallman
Jason Monteiro
Production Coordinator
Arvindkumar Gupta
Cover Work
Arvindkumar Gupta
James Cook is a Java software developer from London, England. He is currently touring Australia. He has developed software ranging from banking and mobile applications to games. He has worked for large gaming companies, such as Electronic Arts, Playfish, and Plumbee.
During the day, he can be found working on rapid application prototyping for new social casino experiences. However, during the night, he collaborates with his longtime working partner, Dan Smallman, for Super Cookie Games to create games such as Super Bomb Noms, OMG Dancer!, and BetamaxâSherbet Plains.
Super Cookie Games started out as a simple endeavor for James and Dan to learn how to make games and deliver them to Android, iOS, and the Web. Choosing LibGDX as the platform was a key component for the success of this duo, with six different games across three app stores culminating in 50,000 downloadsâa testament to LibGDX and its brilliant feature set and ability.
Pavel Czempin is currently completing an internship in the software field and plans to study engineering at a German university. Most of his programming experience stems from his early enrollment in a bachelor's course in computer science. In his free time, he likes to program and develop games.
You can find some of his pro...