Edit moved to C++ as this is happening with non-Cocos Studio sprites.
I made a test project with 50 sprites, most of which are off the screen to the right side of the layer.
When I move the scene camera to the right, the sprites on the right are not visible. However, if I move the rootNode to the left, then the sprites are visible.
Is this a bug or does something else need to be done to use the camera?
I’m using 3.4 final. My code in the init of HelloWorld:
auto spritebatch = SpriteBatchNode::create("MySprites.png");
addChild(spritebatch);
auto spriteCache = SpriteFrameCache::getInstance();
spriteCache->addSpriteFramesWithFile("MySprites.plist");
Then I create the sprites and add them to the layer. In the onEnter:
I’ve experienced this issue too in cocos2d-x 3.4. It seems as if culling is not taking into account the camera movement, but only the original screen bounds. (Looking at Renderer::checkVisibility() seems to confirm this. I can’t see the camera being used in the visibility calculations).
For the time being, I’m setting #define CC_USE_CULLING 0 in ccConfig.h as a workaround. (Which by the way, creates a compilation error in Label::draw() since the code references a local variable only defined within the #if CC_USE_CULLING ... #endif block. I juste moved that line above the #if. I guess that’s ok, I haven’t tried any labels).
@ArtCoder thanks for the workaround. I changed my project to moving a few layers, but I might use this fix in future projects if they don’t get to this bug in time. Much easier to move a camera instead of several layers.
Yeah, moving the camera is much more convenient! Plus I’ve tried moving the layer, but it seems there’s some weird behavior when you combine that with physics without autoStep. Apparently (and I haven’t spent much time testing this), since I’m stepping the physics world at a different rate than the scene graph tick, the bodies lose synchronization with the nodes they’re attached to.
I fixed camera movement in my commit to my pull request. Feel free to use it if you want to move cocos2d::Camera around. In this commit Sprites check for visibility every frame and camera position is being taken into account when checking for visibility. https://github.com/elvman/cocos2d-x/commit/8f2e35c1415b83928e999895a322f98cecbdc903
I see, that cocos2d-x team has fixed the visibility checking code (Camera::getVisitingCamera()->projectGL). But the Sprite’s and Label’s visibility is still checked only if the FLAGS_TRANSFORM_DIRTY flag is set. Could you please remove the dirty check, so that labels and sprites are visible after the camera has been moved?