LibGDX Game Development Essentials Make the most of game development features powered by LibGDX and create a side-scrolling action game, Thrust Copter Juwal Bose BIRMINGHAM - MUMBAI LibGDX Game Development Essentials Copyright © 2014 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: December 2014 Production reference: 1181214 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78439-929-0 www.packtpub.com Credits Author Copy Editors Juwal Bose Roshni Banerjee Gladson Monteiro Reviewers Pavel Czempin Project Coordinator Lévêque Michel Neha Bhatnagar Sudarshan Shetty Tom Wojciechowski Proofreaders Simran Bhogal Maria Gould Commissioning Editor Dipika Gaonkar Ameesha Green Paul Hindle Acquisition Editor Meeta Rajani Indexer Hemangini Bari Content Development Editor Anila Vincent Production Coordinators Komal Ramchandani Technical Editor Sushma Redkar Madhunikita Sunil Chindarkar Cover Work Komal Ramchandani About the Author Juwal Bose is a game developer, game designer, and technology consultant from the incredibly beautiful state of Kerala in India. He is an active figure in social media and game development SIGs, and he never misses a chance to speak at technical conferences and BarCamps. He conducts technical workshops for engineering students at professional colleges as part of open source initiatives. Juwal is the Director at Csharks Games and Solutions Pvt. Ltd., where he manages research and development, training, and pipeline integration. He has been developing games since 2004 using different technologies, such as ActionScript, Objective-C, Java, Unity, LibGDX, Cocos2D, OpenFL, Unity, and Starling. His team has created more than 400 games to date, and many of the job management games are listed at the top of leading portals worldwide. He was involved in the development of more than 20 LibGDX games, primarily for the Android platform. Juwal writes game development tutorials for GameDevTuts+ and manages the blog of Csharks. His isometric tutorial for GameDevTuts+ was well received and is considered a thorough guide for developing tile-based isometric games. This is his second book and he aims to keep writing and sharing his 10 years of game development experience through more books. His first book, Starling Game Development Essentials, Packt Publishing, was on another exceptional cross-platform game development framework—Starling. Juwal is a voracious reader and likes to travel. His future plans also include writing fiction. Acknowledgments I would like to thank my parents and my wife, Dr. Nidhina Haridas, for inspiring me to aim higher and try harder. My heartfelt thanks go to Eldhose P. Mathew, CEO of Csharks, for allowing me to devote my professional time to work on this book. I would also thank Anila Vincent, Meeta Rajani, and Madhunikita Chindarkar for supporting me and all the other team members at Packt Publishing for giving me this opportunity. A special thanks to Suryakumar for those brainstorming sessions and Kenney for the open source art. This book would not have been possible without the expertise of the technical reviewers Tomasz Wojciechowski, Lévêque Michel, Pavel Czempin, and Sudarshan Shetty. Thank you guys. I would also like to express my deep gratitude to Mario Zechner, without whom such an incredible game framework would not have existed. Mario, you rock. Long live LibGDX! About the Reviewers Pavel Czempin is currently completing school in Germany and plans to study at a university. He has also joined a program to complete some of the advanced courses of computer science. There, among other things, he learned programming in Java. In his free time, he works on programming projects and is interested in developing computer games. You can find some of his projects on his GitHub page at https://github.com/ Valep42. I thank my father for encouraging me to review this book. Lévêque Michel has a Bachelor's degree in Information Technology, and he worked in Java development for 7 years. He is currently working on a LibGDX point-and-click game as a core programmer. I would like to thank the author of this book and the team at Packt Publishing for giving me the opportunity to review this great book. Sudarshan Shetty is a cofounder of Neurolinx Software Technologies along with his wife, Anuradha. He completed his engineering from IIT (BHU) and IIT Bombay. He worked as a sound recordist before getting into programming. He has also worked on Wall Street, developing trading applications. In his free time, he experiments with organic farming and loves to play the guitar with his kids, Shameen and Shamika. To find out more about him, check out his LinkedIn profile at http://in.linkedin.com/pub/sudarshan-shetty/12/756/. Tom Wojciechowski is an independent Java developer currently working on a cross-platform multiplayer mobile game (www.asidik.com/blobrun). He holds a Bachelor's degree in Mathematics and Physics, and he has been a core developer for the popular and award-winning LibGDX, a cross-platform Java game development framework. His current projects and blog can be found at www.asidik.com. www.PacktPub.com Support files, eBooks, discount offers, and more For support files and downloads related to your book, please visit www.PacktPub.com. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. TM https://www2.packtpub.com/books/subscription/packtlib Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books. Why subscribe? • Fully searchable across every book published by Packt • Copy and paste, print, and bookmark content • On demand and accessible via a web browser Free access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access. Table of Contents Preface 1 Chapter 1: Wiring Up 7 Getting started 8 Setting up the Java development environment 8 Installing Eclipse 11 Setting up the Android development environment 12 Installing the ADT plugin and linking the Android SDK with Eclipse 12 Installing the LibGDX support plugins 14 Setting up GWT 14 Installing the RoboVM plugin 14 Installing the Gradle plugin 14 The LibGDX Gradle combo 15 Using the Gradle setup application 16 A Hello World project 17 Importing Gradle projects to Eclipse 18 Running the project 20 Exploring the project 24 Displaying the Hello World text 25 Running demos 26 Running tests 27 The alternate LibGDX setup 29 Summary 30 Chapter 2: Let There Be Graphics! 31 The ThrustCopter game 31 A LibGDX app's life cycle 33 Creating the Thrust Copter project 33 Planning art assets 34 The game scene 35 Populating the game scene 36