Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
LibGDX Game Development By Example

You're reading from   LibGDX Game Development By Example Learn how to create your very own game using the libGDX cross-platform framework

Arrow left icon
Product type Paperback
Published in Aug 2015
Publisher
ISBN-13 9781785281440
Length 280 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
James Cook James Cook
Author Profile Icon James Cook
James Cook
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Getting to Know LibGDX FREE CHAPTER 2. Let's Get These Snakes Out of This Book! 3. Making That Snake Slick 4. What the Flap Is the Hype About? 5. Making Your Bird More Flightworthy 6. Onto the Next Platform...Game 7. Extending the Platform 8. Why Are All the Birds Angry? 9. Even Angrier Birds! 10. Exporting Our Games to the Platforms 11. Third-party Services Index

Moving Sammy the snake

So, we have Sammy the snake on the screen, sitting there, looking snaky. However, it isn't much of a game. If it were, we could finish the book right here! What we need to do now is get that snake slithering across the screen!

First, let's sort out the playing area. Currently, the resolution is 640 x 480 pixels and the snake texture is 32 x 32. This means we have a grid of 20 x 15—derived by dividing up the resolution by the texture (640/32 = 20, 480/32 = 15)— of the different positions the snake head could be in. The reason we are going to do it this way is because the original game moved with a periodic movement of one snake component at a time. We are going to do the same.

Let's define our timer. We are going to start off with an interval of one second between movements. So let's create a constant field:

    private static final float MOVE_TIME = 1F;

Now, define a variable to keep track of the time:

    private float timer = MOVE_TIME...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime