Book Image

LibGDX Game Development By Example

By : James Cook
Book Image

LibGDX Game Development By Example

By: James Cook

Overview of this book

Table of Contents (18 chapters)
LibGDX Game Development By Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

GUI creation with Scene2D


We have our game, but you may be wondering why we haven't done anything with the lifecycle of the game, like we did with Snake. Well, that is because we are going to add new screens that will appear at the start and the end. But before we get on to creating and making the new screens, I want to talk about a really useful set of UI tools LibGDX offers for making UIs, Scene2D. Well, what is it?

According the LibGDX wiki page:

"Scene2d is a 2D scene graph for building applications and UIs using a hierarchy of actors."

At its core, Scene2d is made of three classes:

  • Actor: This contains the position, size (rectangular only), origin, scale, rotation, and color.

  • Group: This is an Actor class that can contain other actors and children.

  • Stage: This class has a Camera class, a SpriteBatch class, and a Group class. It orchestrates the updating, drawing, and input handling for all the children in its Group.

Of course, this wouldn't be LibGDX if it stopped there. There is a whole...