Say I’m trying to create a side-on endless runner type game. Can anyone think of a good way to do the undulating terrain similar to the one in this mockup?
Making the actual height profile is easy enough - just a bunch of sine waves combined. But how to actually draw that in Defold without creating a game object for each vertical line of pixels of the screen.
Without knowing much about your needs, here’s a few ideas:
If you have a bunch of sine functions that generate the height data, why not render a fullscreen quad and use those functions in a fragment shader that outputs color if the current pixel UV.y is below the value from your height function
Lets say you have a texture with the starting height data. When you want to add a new column, start by copying the texture x columns to the left where x is the number of columns you want to shift in. I would use a rendertarget and a scratch texture with the same sizes.
Set the scratch texture as target to write to.
Set the texture with the current height data as input to a fragment shader (or material I guess)
Render a quad / sprite over the rendertarget and sample pixels with a UV offset that corresponds to the amount of pixels you are shifting in.
You should have a shifted copy of the height data now
Render a sprite per incoming column that is placed on the column you want new height data. The sprite dimensions should be one pixel width and whatever height you want.
Use the texture from the write RT in a shader that renders it to a fullscreen quad.
Next frame, switch the read and write textures so you copy from the updated data.