I would like to create a climb based game, so I need to have a big scene and a camera that cover only a little part of it and chase my player. This image explains easier what I want:


How can I do it? I'm trying to resize my camera size only, but I don't get the desired result.

Thank you. s.

  • \$\begingroup\$ Can you provide some small code snippet on how you are doing the re-sizing? \$\endgroup\$ – XiaoChuan Yu Jun 8 '13 at 21:21
  • \$\begingroup\$ @XiaoChuanYu I'm try to change my width and height variables. static final int CAMERA_WIDTH = 720; static final int CAMERA_HEIGHT = 480; and new BoundCamera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT, 0, CAMERA_WIDTH, 0, CAMERA_HEIGHT); \$\endgroup\$ – Ste_ Jun 8 '13 at 22:07

Your idea is correct. The scene can be as big as you want. In fact, you don't need to bound it. You just create the correct camera and then set camera.setChaseEntity(mainEntity);

But you are not creating the camera correctly. Look at the constructor:

public BoundCamera(final float pX, final float pY, final float pWidth, final float pHeight, final float pBoundMinX, final float pBoundMaxX, final float pBoundMinY, final float pBoundMaxY) {
    super(pX, pY, pWidth, pHeight);
    this.setBounds(pBoundMinX, pBoundMinY, pBoundMaxX, pBoundMaxY);
    this.mBoundsEnabled = true;

In your case you need to set:


This example is doing exactly what you want (and more).

| improve this answer | |
  • \$\begingroup\$ can you explain meaning of SCENE_MIN and SCENE_MAX constant? :) Thank you! \$\endgroup\$ – Ste_ Jun 9 '13 at 8:24
  • \$\begingroup\$ BoundCamera can move only from pBoundMinX to pBoundMaxX (resp. the same for Y), so if you want the camera to follow your entity, this will tell the camera to stop following it if it is out of bounds. SCENE_MIN/MAX in your case are the bounds of the playable area that you call Scene in your image. \$\endgroup\$ – MartinTeeVarga Jun 9 '13 at 8:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.