Libgdx Backends
Total Page:16
File Type:pdf, Size:1020Kb
Learning LibGDX Game Development Second Edition Wield the power of the LibGDX framework to create a cross-platform game Suryakumar Balakrishnan Nair Andreas Oehlke BIRMINGHAM - MUMBAI Learning LibGDX Game Development Second Edition 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 authors, 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: September 2013 Second edition: January 2015 Production reference: 1220115 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78355-477-5 www.packtpub.com Credits Authors Project Coordinator Suryakumar Balakrishnan Nair Neha Bhatnagar Andreas Oehlke Proofreaders Reviewers Ting Baker Juwal Bose Simran Bhogal Yunkun Huang Maria Gould Stéphane Meylemans Ameesha Green Chris Moeller Paul Hindle Commissioning Editor Indexer Kartikey Pandey Mariammal Chettiyar Acquisition Editors Graphics Subho Gupta Abhinash Sahu Kartikey Pandey Production Coordinator Content Development Editor Alwin Roy Arun Nadar Cover Work Technical Editor Alwin Roy Shashank Desai Copy Editors Relin Hedly Neha Karnani Nithya P About the Authors Suryakumar Balakrishnan Nair is an engineering graduate from Cochin University of Science and Technology, Cochin, India with a specialization in computer science. He just loves programming and likes to keep on experimenting. He has designed a dozen games on the Android platform using LibGDX. He loves traveling and visiting various places. He reads articles and books on a range of issues from politics to environment. He is currently working as a full-time Android game developer for an Indian game company, Csharks (http://csharks. com/site/). I would like to thank my colleagues in Csharks for providing me with moral support, especially Vipin TP and Dheeraj S. I would also like to thank my dear friend Rahul Satish who helped me with the Blender models. Most importantly, I want to thank my mentor, Juwal Bose, who guided me and motivated me for this project. Andreas Oehlke is a professional software engineer and computer scientist who feels very much at home on any Linux/UNIX machine. He holds a bachelor's degree in Computer Science and loves to assemble and disassemble software and hardware alike. The exorbitant affinity for electronics and computers has always been his trademark. His hobbies include game and web development, programming in general (software design and new languages), programming embedded systems with microcontrollers, playing sports, and making music. He currently works full time as a software engineer for a German financial institution. Furthermore, he has worked as a consultant and game developer in San Francisco, CA. In his spare time, he provides his expertise to a German start-up called Gamerald (http://www.gamerald.com/). I want to thank my parents, Michael and Sigrid, and my brother Dennis for their constant and invaluable support, which definitely kept me on the go while writing this book. I also want to thank my close friends for giving me lots of helpful feedback, notably Sascha Björn Bolz for providing the artwork for Canyon Bunny. Last but not least, I want to thank Klaus "keith303" Spang for providing the music track, the whole team of Packt Publishing, and all the numerous reviewers for their great work who helped me produce a high-quality book. About the Reviewers 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 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 as well as training and pipeline integration in his area of expertise. He has been developing games since 2004 using multiple technologies, including 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 has been part of 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' games. His isometric tutorial for GameDevTuts+ was well received and is considered a thorough guide to developing tile-based isometric games. Juwal has written LibGDX Game Development Essentials, Packt Publishing, and reviewed a couple of books as well. The first book he had written, Starling Game Development Essentials, Packt Publishing, is based on another exceptional cross-platform game development framework called Starling. Juwal is a voracious reader and likes to travel. His future plans also include writing fiction. Yunkun Huang is a senior software engineer with more than 7 years of experience in Java development. His research interests include game development, swarm intelligence, automated trading, and enterprise application development. He works for ThoughtWorks as a Java developer now. For more information about his background and research, you can visit his home page http://www.huangyunkun.com/. Stéphane Meylemans has a bachelor's degree in information technology. He worked in web development for 8 years and then decided to move on to game development (mobile and desktop). He has learned Unreal Engine and Unity Game development and is currently working on a LibGDX-based point n click adventure game for which he is writing the story. I would like to thank the author for this great book. It's very useful and well written. It helped me a lot to develop in LibGDX and I recommend it to anyone with Java knowledge who wants to start developing in LibGDX. Chris Moeller is a founder of the game studio Ackmi Design and Engineering. He has been building computers since the age of 9 and has been programming for more than 10 years. He has had the opportunity to work for software companies as a PHP developer, Java QA engineer, and a Flash developer, and he currently works primarily in Java on LibGDX-based applications. He has been an enthusiastic gamer for most of his life and loves many of John Carmack's and early Blizzard games. From these inspirations, he has created many games and game prototypes in several different programming languages. He writes game programming tutorials on his blog at http://chris-moeller. blogspot.in/, and most of his new games can be found on his company website at http://ackmi.com/, which he runs with his wife, Megan. 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: Introduction to LibGDX and Project Setup 9 Diving into LibGDX 10 Features of LibGDX 1.2.0 11 Graphics 11 Audio 12 Input handling 12 File I/O and storage 12 Math and physics 13 Utilities 13 Tools 13 Getting in touch with the community 14 Prerequisites to install and configure LibGDX 14 Java Development Kit 15 Eclipse – Integrated Development Environment 19 Downloading LibGDX 20 Installing Android SDK 21 Running Eclipse and installing plugins 30 Creating a new application 37 Using the old setup tool 37 Using the Gradle-based setup 46 gdx-setup versus gdx-setup-ui 52 Kicking your game to life 54 Key to success lies in planning 56 Game project – Canyon Bunny 57 Description of the game 58 Summary 59 Table of Contents Chapter 2: Cross-platform Development – Build Once,