title: Chase player with camera in AndEngine and limit world's bounds
body: <p>Using AndEngine for Android, I would like to have my scene look like this:</p>
  
  <p><img src="https://i.stack.imgur.com/CI4eE.png" alt="enter image description here"></p>
  
  <p>The red box is the world which must be limited to a given size, say <code>2000px*450px</code>.</p>
  
  <p>The blue box is the <code>Camera</code>, which is limited as well (as usual), for example to <code>750px*450px</code>.</p>
  
  <p>For the whole scene, I have a background image that is exactly <code>450px</code> high. So my <code>Camera</code> can be scaled to whatever size is appropriate, but the background must exactly fit to the height. The width of the <code>Camera</code> may be variable.</p>
  
  <p>The player (circle) must always be in the center (horizontally) but may not leave the world's boundaries.</p>
  
  <p>To achieve this, I've tried adding two types of sizes:</p>
  
  <ul>
  <li>camera size (<code>CAMERA_WIDTH</code>, <code>CAMERA_HEIGHT</code>)</li>
  <li>world size (<code>WORLD_WIDTH</code>, <code>WORLD_HEIGHT</code>)</li>
  </ul>
  
  <p>And this function was to add boundaries to the world so that the physics engine prevents the player from leaving those boundaries:</p>
  
  <pre><code>private void createWorldBoundaries() {
      Body body;
      final Rectangle wall_top = new Rectangle(0, WORLD_HEIGHT-5, WORLD_WIDTH, 10, mVertexManager);
      final Rectangle wall_bottom = new Rectangle(0, 5, WORLD_WIDTH, 10, mVertexManager);
      final Rectangle wall_left = new Rectangle(5, 0, 10, WORLD_HEIGHT, mVertexManager);
      final Rectangle wall_right = new Rectangle(WORLD_WIDTH-5, 0, 10, WORLD_HEIGHT, mVertexManager);
      body = PhysicsFactory.createBoxBody(mPhysicsWorld, wall_top, BodyType.StaticBody, new PhysicsFactory.createFixtureDef(0.0f, 0.5f, 0.5f));
      wall_top.setUserData(body);
      body = PhysicsFactory.createBoxBody(mPhysicsWorld, wall_bottom, BodyType.StaticBody, new PhysicsFactory.createFixtureDef(0.0f, 0.5f, 0.5f));
      wall_bottom.setUserData(body);
      body = PhysicsFactory.createBoxBody(mPhysicsWorld, wall_left, BodyType.StaticBody, new PhysicsFactory.createFixtureDef(0.0f, 0.5f, 0.5f));
      wall_left.setUserData(body);
      body = PhysicsFactory.createBoxBody(mPhysicsWorld, wall_right, BodyType.StaticBody, new PhysicsFactory.createFixtureDef(0.0f, 0.5f, 0.5f));
      wall_right.setUserData(body);
      attachChild(wall_top);
      attachChild(wall_bottom);
      attachChild(wall_left);
      attachChild(wall_right);
  }
  </code></pre>
  
  <p><strike>But this is not working, unfortunately.</strike> (see edit)</p>
  
  <p>Setting the camera to chase the player has the wrong result for me: The player does really stay in the center of the screen all time, but I want the player only to stay in the center horizontally, not vertically.</p>
  
  <p>What am I doing wrong and what can I change? And the basic question is: How can I make the world wider than the camera view, while the height is equal to the camera view. The result should be that you can horizontally walk through your world (moving camera) and you can always see the full height.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>As you define the coordinates of the <code>Rectangle</code>'s center and not its top-left corner, you have to do it like this, it seems:</p>
  
  <pre><code>final Rectangle wall_top = new Rectangle(WORLD_WIDTH/2, WORLD_HEIGHT-1, WORLD_WIDTH, 2, mVertexManager);
  final Rectangle wall_bottom = new Rectangle(WORLD_WIDTH/2, FIELD_BASELINE_Y+1, WORLD_WIDTH, 2, mVertexManager);
  final Rectangle wall_left = new Rectangle(1, WORLD_HEIGHT/2, 2, WORLD_HEIGHT, mVertexManager);
  final Rectangle wall_right = new Rectangle(WORLD_WIDTH-1, WORLD_HEIGHT/2, 2, WORLD_HEIGHT, mVertexManager);
  </code></pre>
  
  <p>However, I had found the other solution in several tutorials. Are these authors not testing their code before writing the tutorials or did the behaviour change from GLES1 to GLES2 or with any recent version?</p>