Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
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
Cocos2d-X Game Development Blueprints

You're reading from   Cocos2d-X Game Development Blueprints Build a plethora of games for various genres using one of the most powerful game engines, Cocos2d-x

Arrow left icon
Product type Paperback
Published in Jul 2015
Publisher Packt
ISBN-13 9781783985265
Length 392 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Karan Sequeira Karan Sequeira
Author Profile Icon Karan Sequeira
Karan Sequeira
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. A Colorful Start FREE CHAPTER 2. How to Fly a Dragon! 3. Not Just a Space Game 4. Back to the Drawing Board 5. Let's Get Physical! 6. Creativity with Textures 7. Old is Gold! 8. Box2D Meets RUBE 9. The Two Towers 10. Cross-platform Building Index

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...
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
Banner background image