Godot Version
4.3
Question
Hi, everyone!
I make an endless runner game in a countryside setting. So, the background is presented by several tilemap layers: grass, trees, houses and so on. As I need it to repeat infinitely, I’ve placed it into a ParalaxLayer and mirrored the Layer at 10 * viewport width (12800 px). No camera node, background just moves from right to left within the viewport (the subviewport to be precise).
Unfortunately, on the half of the running cycle the game starts lagging with freezes and kind of jittering. But when the background reaches a new cycle, the lags disappear.
I’ve made some research. At first, I disabled Vsync. It made the game even more laggy but let me saw that FPS drop from 700 to 70 as the character (so the background) runs forward and reset to 700 when the new cycle begins. Then I tried to isolate the problem deleting all obstacles and background tilemap layers except the one. The absolute values became higher, but the drop persisted, now it was like from 4000 to 400. Only when I got rid of the last tilemap layer in favor of a Sprite2d, the problem disappeared and FPS became stable.
So, it makes me think that lots of tiles within a long paralax background somehow create a huge load on the engine. Now I’m thinking about merging some tilemap layers together or even some sort of baking (make the whole background as several big sprites). But it will be quite demanding and inconvenient in terms of further development, so I’ve decided to ask you for help. Did anyone faced similar problem? Maybe I’m missing something and there is a simple solution?
Thanks in advance!
P.S. I also tried to make chunks of tilemap layers and terminate them as they go out of screen, to free memory, but in that case they won’t appear in the next cycle.


