How to make infinitie background for an space shooter !?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By RezaPouya
:warning: Old Version Published before Godot 3 was released.

Hi , I am making a simple space shooter just to understand how Godot is working , but I can’t make infinite background ( parallex background ) …
I saw some tutorial about this issue but none of them are useful …

I don’t use any camera node in my game ( this is simple game , I just want to show View port and there is no real movement in game )

and I separated all Entities in game as individual scene ( Player , Asteroids , Backgrounds , … )

A better option is to set Mirroring in your parallax layer Reddit - Dive into anything

jarlowrey | 2018-07-07 04:05

:bust_in_silhouette: Reply From: ericdl

For a proper infinite background, you need a camera2d and parallax layers. But since your game has no movement, you can simply tile your background sprite by enabling the Mirrored Repeat texture flag in your sprite’s texture settings, then enabling the Region property and extending the Region Rect boundary.

sprite settings
sprite flags

Hi , thanks …
What’s about performance !?

My original solution was to make an small scene with just a sprite an 3*3 pixel image , then I generate background star nodes with it ( of curse I destroy the nodes after they went out from viewport ) , so which method is better for memory and CPU !?

RezaPouya | 2016-06-20 23:37

Performance should not be an issue with the mirrored repeat/region rect method, especially if there is no movement in your game. As a simple test, I wrote a small script that doubles the size of a background sprite region rect once per second, and on my crappy laptop it experienced severe tearing when the rect reached width of 134217728 pixels.

I don’t know about your method of background star nodes since I have not seen the code, but if you are worried about performance with it, you might try moving or re-positioning the nodes instead of constantly creating and destroying them. It would be interesting to see a comparison of our two methods, although ultimately I think any performance gains are negligible.

Even a parallax background with motion is fairly performant as long as you have a limited number of parallax layers. But a large number of parallax layers will degrade performance noticeably due to overdraw issues.

ericdl | 2016-06-21 14:11