LibGDX - Scrolling Texture Y-Axis

Hi there,

I’m looking for the simplest way to scroll a texture downward with repeat on the Y-Axis. (For example, rain constantly repeating)
(Full examples please)

Thanks!

  • A

I would say the simplest way is to draw it twice, one above the other, both constantly moving downward. once the first one is just off the bottom of the screen, make them both jump back to the top.

with opengl you could use the texture state :

repeat Y coord : [icode]glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT )[/icode], then just increment https://www.opengl.org/sdk/docs/man2/xhtml/glTexCoord.xml along Y.

ofc you could also use a fragment shader.

I did this recently:

Render one image at y-position 0, and another at y-position Gdx.graphics.getHeight(). Every frame, for each texture, subtract an amount, scrollRate*Gdx.graphics.getDeltaTime() from the y-pos of each texture. Every frame, check whether the y-position of the bottom texture is equal to or less than -(negative) screenHeight , and if so, set it equal to screenHeight.

additionally: You can also use just one Texture. If your texture has repeating patterns of say 20px for example. You could create a texture with height equal to the screenheight and add one of those patterns on top. Have the texture start at y=0 and move it down and when it reaches y=-20 start over again.

You can also use multiple textures and give them different scroll speeds which can give a cool effect.

Okay I’m not a fan of self promotion, but here is an example from a game I’m working and where i used the above described method on and though i post it here. Maybe it’ll give you some extra ideas.

At 0:30