How does infinite scroll with UV work?

Hi,

I’m using libGDX and I copy/pasted some endless-scroll code that seems to work:


scrollTimer += delta;

if (scrollTimer > 1.0f)
    scrollTimer = 0.0f;
	                
sStars.setU(scrollTimer);
sStars.setU2(scrollTimer+1);

It works, but stars fly too fast. I’d like to tweak it, but I can’t find in the docs the meaning of setU and setU2. Googling around I found that it probably has got something to do with UV mapping, i.e. X and Y coordinates in texture, but I can’t figure out how it works.

In the code I copied, scrollTimer goes from 0 to 1, so setU() is called with values in interval 0-1 and setU2() is called with interval 1-2. But what does all that mean?

perhaps do something like this


+ float SPEED = 1; //if smaler than 1 it is slower if greater faster

scrollTimer += delta * SPEED;

if (scrollTimer > 1.0f)
-    scrollTimer = 0.0f;
+    scrollTimer = scrollTimer - 1;
                   
sStars.setU(scrollTimer);
sStars.setU2(scrollTimer+1);

I see, this is how I could modify speed. Thanks.

But, my real question is what does setU actually do?

Sets starting and ending U coordinate from texture UV.

Every texture UV is starting with 0 and ending with 1, if GL_REPEAT is used while loading, texture coordinates greather than 1 will “loop” the texture.