Building a 3D Game with LibGDX - Sebastian Di Giuseppe - E-Book

Building a 3D Game with LibGDX E-Book

Sebastian Di Giuseppe

0,0
25,19 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Learn how to build an exciting 3D game with LibGDX from scratch

About This Book

  • Implement an exhaustive list of features that LibGDX unleashes to build your 3D game.
  • Write, test, and debug your application on your desktop and deploy them on multiple platforms.
  • Gain a clear understanding of the physics behind LibGDX and libraries like OpenGL and WebGL that make up LibGDX.

Who This Book Is For

If you are a game developer or enthusiasts who want to build 3D games with LibGDX, then this book is for you. A basic knowledge of LibGDX and Java programming is appreciated.

What You Will Learn

  • Learn the potential of LibGDX in game development
  • Understand the LibGDX architecture and explore platform limitation and variations
  • Explore the various approaches for game development using LibGDX
  • Learn about the common mistakes and possible solutions of development
  • Discover the 3D workflow with Blender and how it works with LibGDX
  • Implement 3D models along with textures and animations into your games
  • Familiarize yourself with Scene2D and its potential to boost your game's design

In Detail

LibGDX is a hugely popular open source, cross-platform, Java-based game development framework built for the demands of cross-platform game development. This book will teach readers how the LibGDX framework uses its 3D rendering API with the OpenGL wrapper, in combination with Bullet Physics, 3D Particles, and Shaders to develop and deploy a game application to different platforms

You will start off with the basic Intellij environment, workflow and set up a LibGDX project with necessary APIs for 3D development. You will then go through LibGDX's 3D rendering API main features and talk about the camera used for 3D.

Our next step is to put everything together to build a basic 3D game with Shapes, including basic gameplay mechanics and basic UI. Next you will go through modeling, rigging, and animation in Blender. We will then talk about refining mechanics, new input implementations, implementing enemy 3D models, mechanics, and gameplay balancing.

The later part of this title will help you to manage secondary resources like audio, music and add 3D particles in the game to make the game more realistic. You will finally test and deploy the app on a multitude of different platforms, ready to start developing your own titles how you want!

Style and approach

A step by step guide on building a 3D game with LibGDX and implementing an exhaustive list of features that you would wish to incorporate into your 3D game

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 178

Veröffentlichungsjahr: 2016

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Building a 3D Game with LibGDX
Credits
About the Author
www.PacktPub.com
eBooks, discount offers, and more
Why subscribe?
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. Setting Up Your Development Environment
LibGDX 3D API overview
Downloading IntelliJ IDEA Community Edition
LibGDX project setup
Basic use of IntelliJ IDEA with LibGDX
Running the Android app
Running the desktop app
Summary
2. An Extra Dimension
Camera techniques
Drawing a cube
Translation
Rotation
Scaling
Summary
3. Working toward a Prototype
Creating our world
Creating our structure
Game screen
A simple playground
Game world
Adding visuals
Introduction to Ashley
Components
Model component
Systems and Ashley's engine
Render system
Adding physics and collisions
Bullet Physics and Bullet system
Creating a scene
Movable characters
Player component
Player system
Adding enemies
Enemy component
Status component
Enemy system
Enemy collision
Making our player able to shoot
Scene2D
Default skin for Scene2D
Health bar
Crosshair
Displaying scores
Pausing the game
Game over widget
Screens
Main menu screen
Leaderboards screen and the Settings class
Summary
4. Preparing Visuals
Setting up Blender
Downloading and installing Blender
Blender's (very) basics
Move gizmo
Scale gizmo
Rotation gizmo
Sketching
Game asset pipeline in Blender
Modeling
UV mapping
Texturing
First steps to animation - rigging
Animation
Exporting
Summary
5. Starting to Look Like an Actual Game
Models usable and ready to deploy with LibGDX
Downloading Fbx-Conv
Command-line usage
Options/flags:
Adding our own gun model
Converting our gun model file
Importing the model, finally!
Adding our own static arena
Creating our model
Importing to our game and getting the collision bounds
Enemy models!
Getting models from the Internet
Preparing for more than one animation
Run animation
Death animation and system
Improving the spawn function
Adding a SkyDome
Getting the model
Implementing
Shadows and lights
Adding a directional shadow with a light
Summary
6. Spicing Up the Game
3D particles and LibGDX 3D particle editor
Particle effect types
Emitter properties
Saving and importing
Adding the particle effect and a material attribute
Mobile performance
Testing on Android
Performance improvements on the enemy model
Performance improvements and frustum culling
UI tweening
Online leaderboards and the .NET API
Analog sticks on mobile and platform recognition
Summary
7. Final Words
Deploying to platforms
Running and deploying on desktop
Running and deploying on Android
Troubleshooting common problems
Gradle
Antivirus
IntelliJ
What's missing from our game?
More platforms
Loading screen and loading feature
About section
Splash screen
UI customization and screen transitions
Game design
Attack system
Shaders and shadows across all platforms
Shooting lasers
Positional audio
Publishing
Ads
Social networks
Summary

Building a 3D Game with LibGDX

Building a 3D Game with LibGDX

Copyright © 2016 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: August 2016

Production reference: 1220816

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham 

B3 2PB, UK.

ISBN 978-1-78528-841-8

www.packtpub.com

Credits

Authors

Sebastián Di Giuseppe

Andreas Krühlmann

Elmar van Rijnswou  

Copy Editor

Zainab Bootwala

Reviewer

Jean-Baptiste Simillon

Project Coordinator

Izzat Contractor

Commissioning Editor

Amarabha Banerjee

Proofreader

Safis Editing

Acquisition Editor

Aaron Lazar

Indexer

Tejal Daruwale Soni

Content Development Editor

Anish Sukumaran

Graphics

Abhinash Sahu

TechnicalEditor

Kunal Chaudhari

Production Coordinator

Aparna Bhagat

About the Author

Sebastian Di Giuseppe started back in 2011 with Java game development and native Android development. With a huge passion, he spent a lot of time learning the different areas of game development, exploring programming areas, and creating prototypes of all kinds for several platforms. With a good plan for his improvement while having a full time job as an Android developer, he also spends a lot of time on the forum, java-gaming.org, learning and making contacts. He joined forces with a graphic designer and a musician to peruse more professional tasks and updates on their work that led him to meet a team of developers who called themselves Deeep Games. With them, he took a step up and also learned project and product management. With time, he joined and consulted other game development teams on management and processes. He now works as a full-time project and product manager and you can see him hang out on the Indie Game Developers' Facebook group posting updates on prototypes, ideas, or recruiting for future projects. You check out his LinkedIn profile at https://ar.linkedin.com/in/sebadigiuseppe or his Facebook profile at https://www.facebook.com/sebastian.digiuseppe.54.

I'd like to thank, Elmar Van Rijnswou and Andreas Krülmann for inviting me to join Deeep Games, which was a huge boost to my career. Packt Publishing, along with Aaron Lazar and Anish Sukumaran take a huge gratitude from me for being so patient, helpful, and supportive on the project, and for giving me this huge opportunity. Also, thanks to Oliver Mendoza for helping synthesize an easy and representative 3D model development along with its other areas.

www.PacktPub.com

eBooks, discount offers, and more

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.

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 PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Preface

Building a 3D Game with LibGDX is a book about how to create games with LibGDX that can work in 3D. We'll cover camera differences with 2D primitive shapes, a game design “on the run” approach, modeling our assets, getting assets from websites, preparing our models and downloading them to be used with LibGDX, animations, textures, a basic UI and with Tweening, all toward developing a basic FPS game. And finally, we will get to export to a desired platform along with troubleshooting usual problems.

What this book covers

Chapter 1, Setting Up Your Development Environment, will cover everything we need to install in order to have a workflow.

Chapter 2, An Extra Dimension, will go over the differences between a 2D and a 3D camera, and then set up a base to work with and draw primitive shapes.

Chapter 3, Working toward a Prototype, will go over the creation of a prototype, from the creation of a level with enemies, chase mechanics, physics, collisions, a user interface, and a mechanism to defend ourselves from the enemies.

Chapter 4, Preparing Visuals, will walk us through the basics of how to use Blender and go step by step through how to create a representative model for our game.

Chapter 5, Starting to Look Like an Actual Game, will help you prepare and import the model created in the previous chapter as well as from other sources. We will also get collision shapes from a static model and add basic shadows.

Chapter 6, Spicing Up the Game, will help you polish your game a little by adding a particle system and some UI Tweening. You will also work a bit on the performance of the game and explore the .NET API, brought by LibGDX, by adding online Leaderboards.

Chapter 7, Final Words, will demonstrate deploying games on various platforms and some basic troubleshooting. This chapter will also help you identify the platform we are running the game on, and finally, talk about room for improvement.

What you need for this book

For this book we'll need the following:

Intellij IDEA Community Edition, at least version 14.1.4LibGDX's Setup App, at least version 1.6.4Java JDKAndroid SDK with at least API 22

Who this book is for

If you are a game developer or an enthusiast who wants to build 3D games with LibGDX, then this book is for you. Some basic knowledge of LibGDX and Java programming is required.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply e-mail [email protected], and mention the book's title in 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 at 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 this book 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.

You can download the code files by following these steps:

Log in or register to our website using your e-mail address and password.Hover the mouse pointer on the SUPPORT tab at the top.Click on Code Downloads & Errata.Enter the name of the book in the Search box.Select the book for which you're looking to download the code files.Choose from the drop-down menu where you purchased this book from.Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR / 7-Zip for WindowsZipeg / iZip / UnRarX for Mac7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Building-a-3D-Game-with-LibGDX. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from http://www.packtpub.com/sites/default/files/downloads/Buildinga3DGamewithLibGDX_ColorImages.pdf.

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 could 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 to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted 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 [email protected] 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

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.

Chapter 1. Setting Up Your Development Environment

LibGDX's development is very powerful, and that is why we will set up a nice and stable structure to work with before jumping into the code and project structure. We will use IntelliJ IDEA to do most of our development for the simply because it's productive (and of course, there are few neat tricks to combine with LibGDX), though it's very common to use Eclipse for development too. There are other ways to set up a 3D game with LibGDX, but to start off this book; we will build the game with basic assets created by code. In this chapter, we will explain how to download and set up all the required tools to get you started with setting up an environment to build 3D games with LibGDX, and to work on desktop and Android platforms. Although LibGDX also builds for HTML (WebGL) and iOS, we won't cover these builds because they do not fit with our game, but they are as easy as the following documentation guidelines on the official site (http://libgdx.badlogicgames.com/). You will learn more about this in this chapter.

Assuming you know LibGDX, you already have the Java Development Kit (JDK) installed and the Android software development kit (SDK) updated (you need API 22 with the LibGDX version [1.6.4]); otherwise, a simple Google search will do. The steps are OS-free and we will use Windows to implement them.

We will cover the following topics in this chapter:

Downloading and installing IntelliJ IDEASetting up the LibGDX project and importing it to IntelliJ IDEARunning and debugging the game

LibGDX 3D API overview

LibGDX is a Java cross-platform game development framework that released its first version in 2009. It lets you go as low-level as you want to and gives you direct access to all kinds of areas of development. It also comes with an OpenGL ES 2.0 and 3.0 wrapper interface, which is the one that lets us perform 3D development.

3D development with LibGDX already has a nice array of games under its belt already. The following screenshot shows a very popular game called Grandpa's Table, which is available on Android, iOS, and Amazon:

The following is a screenshot of an Android game named Apparatus:

The following screenshot is of the game Ingress, which is available on Android and iOS:

These are just a few of the most popular games out there.

We will not only cover as much as we can from this 3D API—to get the most of it and show a general structure for how to keep things organized and optimal—but also the use of other LibGDX tools to get the most of the framework too.

Downloading IntelliJ IDEA Community Edition

Download the latest version of IntelliJ IDEA Community Edition for Java developers from https://www.jetbrains.com/idea/download/; it will suggest the download versions compatible with your current operating system. Select the version that best suits your operating system platform, which will either be 32-bit or 64-bit.

At the time of writing this book, IntelliJ IDEA Community Edition (14.1.4) is the latest version.

LibGDX project setup

At the time of writing this book, LibGDX was in version 1.6.4 and we will use that version. Download the setup app from http://libgdx.badlogicgames.com/download.html and open it:

Set up your project name (ours will be called Space Gladiators) and package name (ours is com.deeep.spaceglad). Enter the game's main class name (ours is Core), set the destination path to your preferred directory, and point out the Android SDK directory location.

We will check the Desktop, Android, and iOS project, but leave out Html since we will use the Bullet physics API, which doesn't work on HTML because of the Google Web Toolkit (GWT) backend (for more information, check out http://www.badlogicgames.com/wordpress/?p=2308).

From Extensions, we'll select Bullet (Bullet physics API), Tools (Bitmap Font Generator [Hiero], 3D Particle Editor, and TexturePacker), Controllers (Controller Input API), and Ashley (Entity System API).

LibGDX comes, as you can see, with a lot of very useful tools that you should use for some time and explore them. We'll cover these selected APIs in some depth over the course of this book.

Click on Generate and wait. After it is done, open IntelliJ IDEA and click on Import Project. Go to your newly created project and look for a file called build.gradle, and IntelliJ will do everything else.

Basic use of IntelliJ IDEA with LibGDX

Running and debugging the app with IntelliJ IDEA is as simple as a click, but sometimes, we need to perform extra configurations on the IDE to avoid exceptions.

Running the Android app

Once IntelliJ is done with all the processes, the default app to run will be Android. To run it, click on the Bug or Play buttons to the right of the navigation bar:

Gradle will build and the Choose Device dialog will pop up, from which you'll choose the Android device on which you'll run the app (either an emulator or a physical device), for which you just have to plug in your device.

Running the desktop app

To run the desktop app we have to change the default configuration and add the desktop launcher:

Click on android and select Edit Configurations; the Run/Debug Configurations dialog should pop up.Click on the + icon at the top left of it and select Application.Name it desktop. In the Main class field, select DesktopLauncher. For Working directory, go to your Android project and double-click the assets folder.Click on the Use Classpath of module field, select desktop, and then click on the OK button at the bottom.

Now instead of android at the top, you'll see desktop. You can run or debug with the two buttons to the right of it.

Summary

In this chapter, we introduced IntelliJ IDEA and its basic use; we also explained how to download and install it, and set up LibGDX Project for 3D work. We configured our work environment and launched the Android application into an actual device and the desktop application.

In the next chapter, we'll take the plunge to it and learn about LibGDX's 3D rendering API, perspective camera, 3D workflow, and more.

Chapter 2. An Extra Dimension

Now that everything is set up, we can move onto the more interesting stuff, (the reason you bought this book), work in three dimensions! This requires new camera techniques: the third dimension adds a new axis instead of having just the x and y grid; a slightly different workflow, and lastly, new render methods are required to draw our game. In this chapter, you'll learn the basics of this workflow to have a sense of what's coming, such as moving, scaling, materials, environment, and some others, and we will move systematically between them, one step at a time.

In this chapter, we will cover the following topics:

Camera techniquesWorkflowLibGDX's 3D rendering APIMath

Camera techniques

The goal of this book is to successfully create a shooter game, as stated earlier. In order to achieve this, we will start with the basics: making a simple first-person camera. We will facilitate the functions and math that LibGDX contains.