Scrolling camera doesn't seem to work how I thought it would.

I watched a video about scrolling platforms and such by doing this.cameras.main.scrollX. I can’t seem to figure out how to make the camera scroll continuously. If I do something like this:

            const cam = this.cameras.main;
            const speed = this.scrollSpeed;
            this.Player.player.setVelocityX(0);
            console.log("here")
            this.scrollOffset += speed;
            cam.scrollX -= speed;

the camera will not scroll at all if I use use “-=” but if I do:

            const cam = this.cameras.main;
            const speed = this.scrollSpeed;
            this.Player.player.setVelocityX(0);
            console.log("here")
            this.scrollOffset += speed;
            cam.scrollX = speed;

Where cam.scrollX is just “=” to speed, it will scroll just once and not scroll again.

I have verified that this code is being called through the update method so that is not the issue. It just doesn’t make sense how I can use “=” but not “-=” to have it continuously scroll.

:wave:

cam.scrollX -= speed; looks right. If you have startFollow() as well you should remove that.

Ok, I have figured out my issue with this, it was because I should’ve had += because I made my camera not go past x = 0. But I have found a different issue, how do you make it so the animation can have a scroll factor of 0? I have turned on the debug mode and I see that the sprite runs out of the hitbox when scrolling

You can’t use setScrollFactor(0, 0) with physics objects, really.