O'Reilly logo

Libgdx Cross-platform Game Development Cookbook by Alberto Cejas Sánchez, David Saltares Márquez

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Building a physics world from level data

Physics for levels can be hardcoded in the source code with terrible consequences for maintenance purposes, but I am sure that you have already heard about the data-driven approach that suggests a solution.

Most level editors include mechanisms to attach physics data to the final level file and one of them, Tiled, is familiar to you from Chapter 8, User Interfaces with Scene2D. It supplies a layers system where you can define geometric shapes and some metadata for their properties.

As all the data is parsed by the map, you can create a generic physics populator for your games so the process of applying them to static bodies becomes almost automatic.

Getting ready

The juice of this recipe is concentrated into ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required