Camera follow for my 2D game


I create a demo project for every game, it is well organized and have most game things.

You can see here:

But i have an issue with camera, that i don’t know what is the best method to solve.

This is the issue:

I want a way to always see everything in the game visible size without use magic numbers for every device.

Can anyone help me?


Can someone help me? The camera is not showing full game size:

void GameScene::setupCamera()
    // zoom
    auto size = Global::getInstance().winSize;

    float zoomFactor = 2.0;
    float zoomX = size.width * zoomFactor;
    float zoomY = size.height * zoomFactor;

    // camera
    auto camera = Camera::createOrthographic(zoomX, zoomY, -1024, 1024);

    // position
    camera->setPosition3D(Vec3(size.width / 2, size.height / 2, 900));
    camera->lookAt(Vec3(size.width / 2, size.height / 2, 0), Vec3(0, 1, 0));

    // replace camera
    _defaultCamera = camera;