Learning Libgdx Game Development
()
About this ebook
Game development is a field of interdisciplinary skills, which also makes it a very complex topic in many respects. One decision that usually needs to be made at the beginning of a game development processis to define the kind of computer system or platform the game will be developed for. This does not pose any problems in general but as soon as the game should also be able to run on multiple platforms it will become a developer's nightmare to maintain several distinct copies of the same game. This is where the libGDX multi-platform game development framework comes to the rescue!
"Learning Libgdx Game Development" is a practical, hands-on guide that provides you with all the information you need to know about the libGDX framework as well as game development in general so you can start developing your own games for multiple platforms. You will gradually acquire deeper knowledge of both, libGDX and game development while you work through twelve easy-to-follow chapters.
"Learning Libgdx Game Development" will walk you through a complete game development cycle by creating an example game that is extended with new features over several chapters. These chapters handle specific topics such as organizing resources, managing game scenes and transitions, actors, a menu system, using an advanced physics engine and many more. The chapters are filled with screenshots and/or diagrams to facilitate comprehension.
"Learning Libgdx Game Development" is the book for you if you want to learn how to write your game code once and run it on a multitude of platforms using libGDX.
ApproachA clear and practical guide to building games in libGDX.
Who this book is forThis book is great for Indie and existing game developers, as well as those who want to get started with game development using libGDX. Java game knowledge of game development basics is recommended.
Andreas Oehlke
Andreas Oehlke is a professional software engineer and a 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. An 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 a game developer in San Francisco, CA. In his spare time, he provides his expertise to a German startup called Gamerald (http://www.gamerald.com/).
Related to Learning Libgdx Game Development
Related ebooks
SFML Blueprints Rating: 0 out of 5 stars0 ratingsMastering SFML Game Development Rating: 0 out of 5 stars0 ratingsHTML5 Game Development with GameMaker Rating: 0 out of 5 stars0 ratingsUnity Game Development Scripting Rating: 0 out of 5 stars0 ratingsOuya Unity Game Development Rating: 0 out of 5 stars0 ratingsGameSalad Essentials Rating: 0 out of 5 stars0 ratingsHaxe Game Development Essentials Rating: 0 out of 5 stars0 ratingsMastering LibGDX Game Development Rating: 0 out of 5 stars0 ratingsSFML Game Development By Example Rating: 0 out of 5 stars0 ratingsCryENGINE 3 Game Development Beginner's Guide Rating: 0 out of 5 stars0 ratingsSFML Game Development Rating: 0 out of 5 stars0 ratingsCRYENGINE Game Development Blueprints Rating: 0 out of 5 stars0 ratingsLibGDX Game Development By Example Rating: 0 out of 5 stars0 ratingsProcedural Content Generation for C++ Game Development Rating: 3 out of 5 stars3/5Unity 5 Game Optimization Rating: 0 out of 5 stars0 ratingsAndroid Game Programming by Example Rating: 0 out of 5 stars0 ratingsGameMaker Programming By Example Rating: 0 out of 5 stars0 ratingsHTML5 Game Development by Example: Beginner's Guide - Second Edition Rating: 1 out of 5 stars1/5OpenGL Game Development By Example Rating: 0 out of 5 stars0 ratingsUnity from Zero to Proficiency (Foundations) Fifth Edition: Unity from Zero to Proficiency, #1 Rating: 5 out of 5 stars5/5Extending Unity with Editor Scripting Rating: 0 out of 5 stars0 ratingsUnity Multiplayer Games Rating: 5 out of 5 stars5/5Mastering Unity 2D Game Development Rating: 5 out of 5 stars5/5Getting Started with Unity 5 Rating: 5 out of 5 stars5/5Mastering Unity 2D Game Development - Second Edition Rating: 0 out of 5 stars0 ratingsA Beginner's Guide to 2D Shooter Games: Beginners' Guides, #2 Rating: 0 out of 5 stars0 ratingsCreating ELearning Games with Unity Rating: 0 out of 5 stars0 ratingsGetting Started with Unity 5.x 2D Game Development Rating: 0 out of 5 stars0 ratingsBuilding an FPS Game with Unity Rating: 0 out of 5 stars0 ratingsSDL Game Development Rating: 0 out of 5 stars0 ratings
Programming For You
Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5HTML & CSS: Learn the Fundaments in 7 Days Rating: 4 out of 5 stars4/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5Hacking: Ultimate Beginner's Guide for Computer Hacking in 2018 and Beyond: Hacking in 2018, #1 Rating: 4 out of 5 stars4/5PYTHON: Practical Python Programming For Beginners & Experts With Hands-on Project Rating: 5 out of 5 stars5/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5Java for Beginners: A Crash Course to Learn Java Programming in 1 Week Rating: 5 out of 5 stars5/5Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS Rating: 0 out of 5 stars0 ratingsPython Projects for Beginners: A Ten-Week Bootcamp Approach to Python Programming Rating: 0 out of 5 stars0 ratingsThe Unofficial Guide to Open Broadcaster Software: OBS: The World's Most Popular Free Live-Streaming Application Rating: 0 out of 5 stars0 ratingsPokemon Go: Guide + 20 Tips and Tricks You Must Read Hints, Tricks, Tips, Secrets, Android, iOS Rating: 5 out of 5 stars5/5Teach Yourself C++ Rating: 4 out of 5 stars4/5SQL: For Beginners: Your Guide To Easily Learn SQL Programming in 7 Days Rating: 5 out of 5 stars5/5The Little SAS Book: A Primer, Sixth Edition Rating: 5 out of 5 stars5/5Python: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5101 Amazing Nintendo NES Facts: Includes facts about the Famicom Rating: 4 out of 5 stars4/5
Reviews for Learning Libgdx Game Development
0 ratings0 reviews
Book preview
Learning Libgdx Game Development - Andreas Oehlke
Table of Contents
Learning Libgdx Game Development
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
Errata
Piracy
Questions
1. Introduction to Libgdx and Project Setup
Diving into Libgdx
Features of Libgdx 0.97
Graphics
Audio
Input Handling
File I/O
Math and Physics
Utilities
Tools
Getting in touch with the community
Prerequisites for installing and configuring
Java Development Kit (JDK)
Eclipse – Integrated Development Environment (IDE)
Downloading Libgdx
Installing Android SDK
Running Eclipse and installing plugins
Creating a new application
Kicking your game to life
Key to success lies in planning
Game project – Canyon Bunny
Description of the game
Summary
2. Cross-platform Development – Build Once, Deploy Anywhere
The demo application – how the projects work together
Backends
LWJGL (Lightweight Java Game Library)
Android
WebGL
Modules
The application module
Logging
Shutting down gracefully
Persisting data
Querying the Android API Level
Querying the platform type
Querying memory usage
Graphics module
Querying delta time
Querying display size
Querying the FPS (frames per second) counter
Audio module
Sound playback
Music streaming
Input module
Reading the keyboard/touch/mouse input
Reading the accelerometer
Starting and canceling vibrator
Catching Android soft keys
The files module
Getting an internal file handle
Getting an external file handle
The network module
HTTP GET and HTTP POST
Client/server sockets
Opening a URI in a web browser
Libgdx's Application Life-Cycle and Interface
Starter Classes
Running the demo application on a desktop
Running the demo application on Android
Running the demo application in a WebGL-capable web browser
The demo application – time for code
Inspecting an example code of the demo application
The create() method
The render() method
The dispose() method
Having fun with the debugger and Code Hot Swapping
Summary
3. Configuring the Game
Setting up the Canyon Bunny project
Using a class diagram for Canyon Bunny
Laying foundations
Implementing Constants
Implementing CanyonBunnyMain
Implementing WorldController
Implementing WorldRenderer
Putting it all together
Building the game loop
Adding test sprites
Adding game world's debug controls
Adding CameraHelper
Adding camera debug controls using CameraHelper
Summary
4. Gathering Resources
Setting a custom Android application icon
Creating texture atlases
Loading and tracking assets
Organizing assets
Testing assets
Handling level data
Summary
5. Making a Scene
Creating game objects
The rock object
The mountains object
The water overlay object
The clouds object
Implementing the level loader
Assembling the game world
Implementing the game GUI
The GUI score
The GUI extra lives
The GUI FPS counter
Rendering the GUI
Summary
6. Adding the Actors
Implementing the actor game objects
Creating the gold coin object
Creating the feather object
Creating the bunny head object
Updating the rock object
Completing the level loader
Adding the game logic
Adding collision detection
Losing lives, game over, and fixing the camera
Adding the game over text and the feather icon to the GUI
Summary
7. Menus and Options
Managing multiple screens
Exploring Scene2D (UI), TableLayout, and skins
Using Libgdx's scene graph for the menu UI
Building the scene for the menu screen
Adding the background layer
Adding the objects layer
Adding the logos layer
Adding the controls layer
Adding the Options window layer
Building the Options window
Using the game settings
Summary
8. Special Effects
Creating complex effects with particle systems
Adding a dust particle effect to the player character
Moving the clouds
Smoothing with Linear interpolation (Lerp)
Letting the rocks float on the water
Adding parallax scrolling to the mountains in the background
Enhancing the game screen's GUI
Event – player lost a life
Event – score increased
Summary
9. Screen Transitions
Adding the screen transition capability
Implementing transition effects
Knowing about interpolation algorithms
Creating a fade transition effect
Creating a slide transition effect
Creating a slice transition effect
Summary
10. Managing Music and Sound Effects
Playing back music and sound effects
Exploring the Sound interface
Exploring the Music interface
Accessing the audio device directly
Exploring the AudioDevice interface
Exploring the AudioRecorder interface
Using sound generators
About the sfxr generator
About the cfxr generator
About the bfxr generator
Adding music and sounds to Canyon Bunny
Summary
11. Advanced Programming Techniques
Simulating physics with Box2D
Exploring the concepts of Box2D
Understanding rigid bodies
Choosing body types
Using shapes
Using fixtures
Simulating physics in the world
Physics body editor
Preparing Canyon Bunny for raining carrots
Adding the new assets
Adding the carrot game object
Adding the goal game object
Extending the level
Letting it rain carrots
Working with shaders in Libgdx
Creating a monochrome filter shader program
Using the monochrome filter shader program in Canyon Bunny
Adding alternative input controls
Summary
12. Animations
Manipulating actors through actions
Actions for manipulating actors
Controlling the order and time of execution
Animating the menu screen
Animating the gold coins and bunny head actors
Animating the menu buttons and options window
Using sequences of images for animations
Packing animations using the texture packer
Choosing between animation play modes
Animating the game screen
Defining and preparing new animations
Animating the gold coin game object
Animating the bunny head game object
Summary
Index
Learning Libgdx Game Development
Learning Libgdx Game Development
Copyright © 2013 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: September 2013
Production Reference: 1190913
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78216-604-7
www.packtpub.com
Cover Image by Aniket Sawant (<aniket_sawant_photography@hotmail.com>)
Credits
Author
Andreas Oehlke
Reviewers
Ebenezer Edelman
Matthias Markowski
David Saltares Márquez
Chris Moeller
Acquisition Editors
Kartikey Pandey
Julian Ursell
Lead Technical Editor
Mayur Hule
Technical Editors
Menza Mathew
Amit Shetty
Harshad Vairat
Copy Editors
Mradula Hegde
Gladson Monteiro
Sayanee Mukherjee
Kirti Pai
Adithi Shetty
Project Coordinator
Apeksha Chitnis
Proofreaders
Paul Hindle
Mario Cecere
Indexer
Rekha Nair
Graphics
Abhinash Sahu
Production Coordinator
Shantanu Zagade
Cover Work
Shantanu Zagade
About the Author
Andreas Oehlke is a professional software engineer and a 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. An 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 a game developer in San Francisco, CA. In his spare time, he provides his expertise to a German startup 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 with regard to providing the artwork for Canyon Bunny. Last but not least, I want to thank Klaus keith303
Spang for providing the music track as well as the whole team from Packt Publishing, including all the numerous reviewers involved, for
their great work in producing a high quality book.
About the Reviewers
Ebenezer Edelman is a British computer programmer currently living in South Africa. He has an eclectic and diverse set of interests ranging from technology, engineering, and science to literature, photography, videography, and music. His hobbies include playing the piano, designing rocket engines, and occasionally a game of chess.
He started game development by learning C from the manual of a C compiler and developing simple text-based games. Then, after getting to grips with C++ and the DirectX SDK, he attempted to develop a 3D physics sandbox game, which never got past the beta stage. After that, he learned C# and the XNA framework and made several 2D games before deciding to get involved in mobile game development. He did this using Java and the LibGDX framework, which he used to get some of his old 2D games to Android. He is constantly looking to broaden his knowledge, and he now uses Research In Motion's open source C++ game engine gameplay3d.
In addition, he has experience of Windows Forms (C#), the GTK+ toolkit (Vala), the Qt toolkit (C++), the Android SDK (Java), as well as the x86 Assembly language, Python, PHP, JavaScript, and HTML/CSS.
His personal website and blog is located at http://EbenezerEdelman.tk/, and he is on Twitter (@EbenezerEdelman) and Google Plus (+EbenezerEdelman).
Matthias Markowski is a passionate game developer and video game enthusiast who focuses on the field of Graphics Programming. He began his professional career in 2005 through his involvement in the demoscene. He has contributed to the development of the fast-paced action MMOG (Massively Multiplayer Online Game) Black Prophecy
and the Wii U casual game Your Shape Fitness Evolved 2013
. He is currently employed at Ubisoft Blue Byte, known as a creator of excellent strategy games, located in Düsseldorf, Germany.
You can view his portfolio and contact details at http://mmarkowski.carbonmade.com.
David Saltares Márquez works at the award-winning developer Crytek as a games programmer. The Nottingham-based studio of the company behind the Crysis series was his jump into the AAA industry in 2012. Since then, he has been part of the Artificial Intelligence team, developing behaviors, pushing character fidelity forward, and developing systems that are now part of CryENGINE.
He obtained his BSc in Computing Science from Cádiz University (Spain) where he founded the games development society (ADVUCA) in collaboration with other passionate classmates. Through the society, he organized several talks and workshops with a strong focus on open source software, all of which were a great success.
By always working on side projects, he the joined the Libgdx community, attracted by the richness of its features, open source nature, multiplatform capabilities, and the hospitality of its developers. Libgdx allowed him to create various games such as Freegemas (https://github.com/siondream/freegemas-gdx) and Math Maze (http://siondream.com/blog/games/math-maze/). In return, he contributed to the maps' API and is very active on the forums.
Further information is available on his blog (http://siondream.com), where he talks in depth about Libgdx, programming, personal projects, and his experience in game jams such as Ludum Dare (http://siondream.com/blog/game-jams/).
Chris Moeller is a founder of the game studio Ackmi Design and Engineering. He has been building computers since the age of nine and has been programming for more than 10 years. He had the opportunity to work for software companies as a PHP developer, Java QA engineer, and Flash developer, and he currently works primarily for Android. He has been an enthusiastic gamer for most of his life and has created many game prototypes as well as several finished games. He writes game tutorials on his blog at www.chrismweb.com, and most of his new games can be found through his company website at www.ackmi.com, which he runs with his wife, Megan.
www.PacktPub.com
Support files, eBooks, discount offers and more
You might want to visit www.PacktPub.com for support files and downloads related to your book.
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
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.
http://PacktLib.PacktPub.com
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across 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 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 nine entirely free books. Simply use your login credentials for immediate access.
Preface
Since personal computers have conquered our private homes, video games have become more and more popular and eventually a multimillion dollar business for big video game companies. With the introduction of mobile devices such as smartphones and tablets, the market for video games has experienced another significant increase; in particular, it has now become open to independent game developers with small budgets.
For game developers, it is essential to have tools at hand that provide fundamentals which allow rapid prototyping and cost-effective implementation of their creative ideas. This is where Libgdx comes into play.
Libgdx, as a Java-based game development framework, provides a unified access layer to handle all the supported platforms. Libgdx also makes use of C/C++ to achieve cross-platform support as well as to boost the application performance for mission critical tasks.
This book will show you how easy it is to develop cross-platform games by walking you through a complete game development cycle using the free and open source library Libgdx. Besides this, you will also learn about common game structure and the involved requirements.
You will be introduced to the key features of Libgdx and you will learn how to develop a game with ease and speed up your development cycles. In ten easy-to-follow chapters, you are going to develop your first Libgdx cross-platform game and add more and more game functionalities as you progress further through this book.
The special features will also make you acquainted with advanced programming techniques such as animations, physics simulations, and shader programs that enhance your games in both their gameplay and visual presentation.
By the end of this book, you will have a fully working 2D game that will run on Windows, Linux, Mac OS X, WebGL-capable browsers, and Android. You will also have all the skills required to extend the game further or to start developing your own cross-platform games.
What this book covers
Chapter 1, Introduction to Libgdx and Project Setup, covers how to install and configure the development environment and introduces you to the project setup tool that comes with Libgdx. Then, we will take a first look at the basics of what a game needs to come alive.
Chapter 2, Cross-platform Development – Build Once, Deploy Anywhere, explains the supported target platforms and how to deploy and run our application on each platform using a demo application. For the first overview of Libgdx's API, we will take a glance at each module. Then, the Application Cycle will be introduced, and we will take a look at how to debug and manipulate our code at runtime.
Chapter 3, Configuring the Game, brings us from our demo application to a real game by setting up a new project called Canyon Bunny. We will work on this project throughout the rest of the book and extend it from chapter to chapter with new features. Since Libgdx is a framework, we will first have to build our program architecture by using UML class diagrams to structure our game engine.
Chapter 4, Gathering Resources, describes how to gather all the resources (assets) needed for Canyon Bunny including graphics, audio files, level data, and so on. We will also find out how to load, track, and organize assets efficiently. Finally, it is time to think about how level data is going to be handled so that we are able to populate our game world with objects.
Chapter 5, Making a Scene, covers how to start implementing the first game objects such as rocks, mountains, and clouds, and how to use the assets that we added in Chapter 4, Gathering Resources. In order to visualize the game scene, a level loader is needed to put our game objects in their right places in the game world. Typically, games have a user interface to give feedback about their current status, so we will add a game GUI to Canyon Bunny that displays the player's high score, remaining extra lives, and so on.
Chapter 6, Adding the Actors, explains how to add the remaining game objects for Canyon Bunny, including the player character and collectible items to complete our game. We will also add simple physics for player movement and basic collision detection. Additionally, the game logic will be extended so that it is able to detect the life lost
and game over
conditions.
Chapter 7, Menus and Options, describes how to create a menu system with widgets such as buttons, labels, and checkboxes to enrich the overall game experience. Furthermore, we will add an Options window where the player can adjust the game settings.
Chapter 8, Special Effects, covers how to make use of particle systems and how to apply interpolation algorithms to create impressive effects such as dust clouds; a smooth, following camera; floating rocks; and parallax scrolling for mountains in the background. Using special effects will spice up the appearance of your game.
Chapter 9, Screen Transitions, introduces screen transitions. We will dive into enhanced visual effects using OpenGL's Framebuffer Objects for offscreen rendering into video memory. This will allow us to create seamless transitions for an improved user experience when switching from one screen to another. For Canyon Bunny, we will create a variety of transition effects.
Chapter 10, Managing Music and Sound Effects, will walk you through a list of recommended sound generators and discuss their differences. Then, we will take a look at Libgdx's Audio API and demonstrate how to use it by creating an audio manager. We do this so that handling all our audio playback needs become a breeze.
Chapter 11, Advanced Programming Techniques, introduces you to some advanced programming techniques that will guide you to the next level of game programming. We will build up basic knowledge about the Box2D API that enables us to create believable physics simulations in games. Additionally, we will discuss the topic of shader programs using the example of a monochrome image filter effect. Lastly, we will show you how to make use of the accelerometer hardware commonly available in modern smartphones and tablets, which allows controlling the game by tilting the device.
Chapter 12, Animations, explains how to polish up the game by adding animations. We will cover two different approaches to animate the game menu and the game world. Finally, we will implement a state machine to allow event-based animations for the player character.
What you need for this book
Libgdx is a cross-platform game development framework. For development, you will need a computer running either Windows (Vista/7/8), Linux (for example, Ubuntu), or Mac OS X (10.5+).
Additionally, you will need to download the Libgdx framework for game development. You can download Libgdx from https://code.google.com/p/libgdx/downloads/list. Please download Version 0.9.7 of Libgdx, as this is the version that is used in this book.
The Integrated Development Environment (IDE) used in this book is Eclipse. You can download the Eclipse IDE from http://www.eclipse.org/.
To develop games for the Android platform, you will need an Android device running Android 2.2 (Froyo) or higher and the official Android Software Development Kit (SDK) that can be downloaded from http://developer.android.com/sdk/index.html.
Who this book is for
This book is written for software developers who are new to game development and to Libgdx in particular. It is assumed that you have some experience in Java to be able to follow the discussed code in this book.
Conventions
In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text are shown as follows: The main class of the demo application is MyDemo.java.
A block of code is set as follows:
@Override
public void dispose() {
batch.dispose();
texture.dispose();
}
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
public void update (float deltaTime) { updateMotionX(deltaTime); updateMotionY(deltaTime);
// Move to new position position.x += velocity.x * deltaTime; position.y += velocity.y * deltaTime;
}
New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: A new tab titled Development Mode should open at the bottom.
Note
Warnings or important notes appear in a box like this.
Tip
Tips and tricks appear like this.
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to <feedback@packtpub.com>, and mention the book title via the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Downloading the example code
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <copyright@packtpub.com> with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
Questions
You can contact us at <questions@packtpub.com> if you are having a problem with any aspect of the book, and we will do our best to address it.
Chapter 1. Introduction to Libgdx and Project Setup
This book will take you on an exciting tour to show and teach you about game development using the open source Libgdx framework. Actually, you have chosen just the right time to read about game development as the game industry is in a remarkable state of change. With the advent of increasingly powerful smartphones and tablets as well as the ever-growing application stores for desktop computers and mobile platforms serving millions of users a day, it has never been easier for Independent Game Developers (also known as Indies) to enter the market with virtually no risks and very low budgets.
In this chapter you will learn about what Libgdx is and what the advantages are to use it for developing your own games. You will also get a brief overview of the feature set that Libgdx provides.
Before you can start developing games with Libgdx, you have to install and set up your development environment accordingly. You will be using the freely available and open source software Eclipse as your Integrated Development Environment (IDE ) and set up a basic project that uses Libgdx. It will feature a runnable example application for each currently supported target platform. These platforms are as follows:
Windows
Linux
Mac OS X
Android (Version 1.5 and above)
HTML5 (Using JavaScript and WebGL)
Note
The target platforms Windows, Linux, and Mac OS X will from now on be referred to as Desktop and also share a project in our development environment.
An alert reader may have noticed that iOS is missing in the list of supported target platforms. Fortunately, it is very likely that Libgdx will support the iOS platform soon as the developers have already put great effort into this feature. At the time of writing of this book, it is said that iOS, starting from Version 5.0 and above, will be supported.
Furthermore, you are going to explore what a game needs by looking at it from a technical standpoint, and why it is so important to plan a game project before the development starts.
At the end of this chapter, you will be introduced to the game project that is going to be developed and enhanced throughout this book.
Diving into Libgdx
Libgdx is an open source, cross-platform development framework, which is designed mainly, but not exclusively,