# Star field parallax

**URL:** <https://forum.defold.com/t/star-field-parallax/67950>\
**Category:** Questions\
**Created:** [March 29, 2021, 9:11am UTC](https://forum.defold.com/t/star-field-parallax/67950 "2021-03-29T09:11:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_8BitSkull](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/alex_8bitskull/32/5424_2.png) [@Alex\_8BitSkull](https://forum.defold.com/u/Alex_8BitSkull)\
**Post date:** [March 29, 2021, 9:11am UTC](https://forum.defold.com/t/star-field-parallax/67950/1 "2021-03-29T09:11:40Z")

</div>

I’m making a top down view space game. I’m using Rendercam.

I need to make a star background with parallax (both position and scale, as you can zoom in and out).

My current solution is to place 9 sprites (3x3) in a game object and child it to the Rendercam game object. I then have a script that handles the movement and scale parallax. The 3x3 seamlessly looping grid means I can recenter the game object after sufficient movement.

I don’t like this solution because it feels janky, and the sprites have to be large to account for the maximum zoom-out.

I’d ideally have 2 or 3 layers (to give the illusion of some stars being closer than others), but would be happy with an elegant single layer solution.

How would you do this?

Hoping to nerd-snipe someone here… 🙏

---

<div class="post-metadata">

**Author:** ![Klear](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/klear/32/11577_2.png) [@Klear](https://forum.defold.com/u/Klear)\
**Post date:** [March 29, 2021, 11:43am UTC](https://forum.defold.com/t/star-field-parallax/67950/2 "2021-03-29T11:43:18Z")

</div>

[This](https://forum.defold.com/t/example-for-parallax-background-with-shader/55981) might be good place to start. I remember I had to modify it a lot of my current project, but I ended up with a very nice parallax effect.

---

<div class="post-metadata">

**Author:** ![Alex\_8BitSkull](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/alex_8bitskull/32/5424_2.png) [@Alex\_8BitSkull](https://forum.defold.com/u/Alex_8BitSkull)\
**Post date:** [March 29, 2021, 11:46am UTC](https://forum.defold.com/t/star-field-parallax/67950/3 "2021-03-29T11:46:41Z")

</div>

That sounds very promising, will check it out. Thanks!

---

<div class="post-metadata">

**Author:** ![roccosaienz](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/roccosaienz/32/19991_2.png) [@roccosaienz](https://forum.defold.com/u/roccosaienz)\
**Post date:** [March 29, 2021, 2:29pm UTC](https://forum.defold.com/t/star-field-parallax/67950/4 "2021-03-29T14:29:55Z")

</div>

Hey Alex,

just a side note. If you are aiming at some realism you don’t need more than ONE background layer; stars are usually very very distant, so distant that you don’t see any parallax in space but the movement of objects (ships, bullets…) against the background. If you are near a planet then the planet may have a different parallax but only it.

But, of course, if you want a 80’s star field scrolling then you need more levels. But it is just a wrong design propagating in the media… 🙂

Ciao!

---

<div class="post-metadata">

**Author:** ![Alex\_8BitSkull](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/alex_8bitskull/32/5424_2.png) [@Alex\_8BitSkull](https://forum.defold.com/u/Alex_8BitSkull)\
**Post date:** [March 29, 2021, 2:34pm UTC](https://forum.defold.com/t/star-field-parallax/67950/5 "2021-03-29T14:34:37Z")

</div>

Point well taken - though very little in this game will be realistic…

---

<div class="post-metadata">

**Author:** ![Klear](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/klear/32/11577_2.png) [@Klear](https://forum.defold.com/u/Klear)\
**Post date:** [March 29, 2021, 2:36pm UTC](https://forum.defold.com/t/star-field-parallax/67950/6 "2021-03-29T14:36:38Z")

</div>

You could always have stars on one layer and space debris, meteorites, comets and stuff on closer ones. That would still be wrong in a lot of ways, but for different reasons.

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [March 29, 2021, 2:54pm UTC](https://forum.defold.com/t/star-field-parallax/67950/7 "2021-03-29T14:54:42Z")

</div>

> [@Alex\_8BitSkull](#):
>
> I don’t like this solution because it feels janky, and the sprites have to be large to account for the maximum zoom-out.

I think this is a perfectly good approach, as long as each sprite aligns properly with each other.

3x3 sprites suggests you can travel both horizontally and vertically I guess?

And by using sprites, I assume you have prerendered textures to switch between?  
Are they all the same texture? (just positioned differently so that you can move and zoom in/out)

In any case, I’d like to highlight the possibility to use a screen space quad, that always  
fills the screen perfectly. I don’t have a small example for you, but perhaps others can help here. Found [this](https://forum.defold.com/t/2d-lighting-in-defold-solved/31387/15) example.  
You can use the shader to zoom in/out by scaling the uv coordinates. By doing so you can also produce multiple layers in the same quad by sampling the texture several times per pixel, each time with a scaled uv coordinate.  
Anyways, just thought I should mention it. (Sounds like a fun task for someone to help experiment with 😉 )
