Potential camera bug?

Potential camera bug?


I’m making an 8-bit inspired pixel game and position the camera so that everything looks 2x the size like so:

auto cam = this->getDefaultCamera();
auto pos = cam->getPosition3D();
cam->setPosition3D(Vec3(pos.x, pos.y, pos.z * (1.0 / GAME_SCALE))); // scale is 2.0

I also made a function that can make sprites of a certain width and height with gfx taken from the same spritesheet I’m using for my background tiles, and for some reason this resets the game’s size to 1x size again. If I run this code:

auto src = Sprite::create("images/tiles.png"); // gfx used in the game as background tiles
auto texture = RenderTexture::create(3, 3, src->getTexture()->getPixelFormat());

Everything is at 1x size again. I run the camera code the last thing I do in the onEnter method.
However, if I run the camera code inside a onTouchBegan method (so after the game started) I can zoom in again.

How can I structure my code so that the game starts at 2x?

One more thing - and I doubt that this is intented behaviour…
If I don’t run the second code block (so the game starts at 2x zoom), then minimize the window, then maximize it again, the zoom is at 1x. Is this a bug…?


What kind of scene are you using?


It’s inherited from the Scene class.


I think you need to call clear() first. Let me think about the rest.


Where should I call clear? Can you post some pseudocode?

auto sprite = Sprite::create("original.png");
auto renderTexture = RenderTexture::create(64, 64, Texture2D::PixelFormat::RGBA8888);
sprite->setAnchorPoint(Vec2(0, 0));
renderTexture->saveToFile("rendertexture.png", Image::Format::PNG);


Adding clear didn’t do anything, sorry.