Generating a world using data exported from RUBE
RUBE exports its level information in a neat and tidy JSON file. We can create a complete physics world from this exported JSON file by using a JSON parser along with a class called b2dJson
. You can find the required files in the RUBE download package as well as in the source bundle for this chapter.
Before we go ahead, let's discuss how our Box2D world will be created for this chapter. We will split the world creation into two main functions: CreateWorld
and CreateGameObjects
. In the CreateWorld
function, we will use the b2dJson
class to create a b2World
object, based on data exported from RUBE. In the CreateGameObjects
function, we will create sprites for all the physics bodies within the world.
Without further ado, let's begin with some code. This is the CreateWorld
function from GameWorld.cpp
:
void GameWorld::CreateWorld(b2dJson* json, int level) { // get file data and parse it to get b2dJson char buf[32] = {0}; sprintf(buf, "Level...