Potential camera bug?

Potential camera bug?
0

#1

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());
texture->begin();
texture->end();

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…?


#2

What kind of scene are you using?


#3

It’s inherited from the Scene class.


#4

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


#5

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


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

#7

Adding clear didn’t do anything, sorry.