Book Image

Cocos2d-X Game Development Blueprints

By : Karan Sequeira
Book Image

Cocos2d-X Game Development Blueprints

By: Karan Sequeira

Overview of this book

Table of Contents (17 chapters)
Cocos2d-x Game Development Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The update loop


We already saw a line from the update function where we step the Box2D simulation. Let's now go over the remaining objects that need to be updated:

void GameWorld::update(float dt)
{
  // update the world
  world_->Step(dt, 8, 3);

  // update all game objects
  clown_->Update();
  if(base_platform_)
  {
    base_platform_->Update();
  }
  
  for(int i = 0; i < num_collectibles_active_; ++i)
  {
    ((Collectible*)active_collectibles_->objectAtIndex(i))->Update();
  }

  // update platform if user is dragging one
  if(platform_->isVisible() && !touch_start_.equals(CCPointZero))
  {
    platform_->setPosition(game_object_layer_->
      convertToNodeSpace(touch_start_));
  }

  // walls must move along with clown
  wall_->SetTransform(b2Vec2(0, clown_->GetBody()->GetPosition().y - 
    SCREEN_TO_WORLD(SCREEN_SIZE.height/2)), 0);
  // background must scroll with respect to clown
  background_manager_->Update( has_game_begun_ ? (...