Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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:

Example

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.

share|improve this question
    
Can you provide some small code snippet on how you are doing the re-sizing? –  XiaoChuan Yu Jun 8 '13 at 21:21
    
@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); –  Ste_ Jun 8 '13 at 22:07
add comment

1 Answer

up vote 3 down vote accepted

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:

new BoundCamera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT, SCENE_MIN_X, SCENE_MAX_X, SCENE_MIN_Y, SCENE_MAX_Y);

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

share|improve this answer
    
can you explain meaning of SCENE_MIN and SCENE_MAX constant? :) Thank you! –  Ste_ Jun 9 '13 at 8:24
    
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. –  sm4 Jun 9 '13 at 8:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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