基于平铺的2D视口/相机

时间:2013-10-29 05:48:15

标签: c++ camera 2d viewport roguelike

这不是一个问题,而是一个“反隧道视觉”检查。

我正在尝试使用roguelike工作的相机/视口,但我不确定我是否正确地做事。

这是我到目前为止的代码:

void Map::moveCamera(int targetx,int targety) {
    //size of the map portion shown on-screen
int CAMERA_WIDTH = 80;
int CAMERA_HEIGHT = 43;

int camera_x = 0;
int camera_y = 0;

    //new camera coordinates (top-left corner of the screen relative to the map)
    int x = targetx - CAMERA_WIDTH / 2;  //coordinates so that the target is at the center of the screen
    int y = targety - CAMERA_HEIGHT / 2;

    //make sure the camera doesn't see outside the map
    if (x < 0){
        x = 0;
    }
    if (y < 0){
        y = 0;
    }

    if (x > map_width - CAMERA_WIDTH - 1) {
        x = map_width - CAMERA_WIDTH - 1;
    }
    if (y > map_height - CAMERA_HEIGHT - 1) {
        y = map_height - CAMERA_HEIGHT - 1;

    if (x != camera_x or y != camera_y) {
        computeFov();
    }
        camera_x = x;
        camera_y = y;
    }
}

现在,当我改变地图的大小时,相机会被困在角落里,我看不到地图!

有人能指出我正确的方向吗?

0 个答案:

没有答案