Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying LibGDX Game Development By Example
  • Table Of Contents Toc
LibGDX Game Development By Example

LibGDX Game Development By Example

By : James Cook
4 (15)
close
close
LibGDX Game Development By Example

LibGDX Game Development By Example

4 (15)
By: James Cook

Overview of this book

LibGDX is a cross-platform game development framework in Java that makes game programming easier and fun to do. It currently supports Windows, Linux, Mac OS X, Android, and HTML5. With a vast feature set on offer, there isn't a game that can’t be made using libGDX. It allows you to write your code once and deploy it to multiple platforms without modification. With cross-platform delivery at its heart, a game can be made to target the major markets quickly and cost effectively. This book starts with a simple game through which the game update cycle is explained, including loading textures onto your screen, moving them around, and responding to input. From there you’ll move on to more advanced concepts such as creating a formal game structure with a menu screen, adding a game screen and loading screen, sprite sheets, and animations. You’ll explore how to introduce a font to optimize text, and with the help of a game that you’ll create, you’ll familiarise yourself with the 2D tile map API to create worlds that scroll as the characters move. In the final sample game of the book, you’ll implement a basic version of an Angry Birds clone, which will allow you to use the physic library box2D that libGDX provides access to. An overview of exporting games to different platforms is then provided. Finally, you will discover how to integrate third-party services into games and take a sneak peak at the Social Media API to get a basic understanding of how it fits into the libGDX ecosystem.
Table of Contents (13 chapters)
close
close
12
Index

More on collisions


You might have found while playing our little game that you can make the snake turn back on itself or it even goes through itself. Anyone who remembers the original will know that this results in an immediate game over!

What we are going to look at now can essentially be split into two parts. First, we will fix the snake's ability to slither back on itself, as seen in the following screenshot:

Second, we will look at stopping the game when the snake collides with another part of its body, as seen in the following screenshot:

Stopping the doubleback

With our snake slithering around, if you change the direction of the snake and you tell it to go back the way it is traveling, it will slide right through itself. This isn't how the game should be!

Essentially, what we want to do is, if the player tells the snake to change its direction and move in the exact opposite direction, ignore that input command.

First, we will create a method to do this precise check:

private void updateIfNotOppositeDirection...
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
LibGDX Game Development By Example
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon