I have a big background ( 2048 X 1440 ) and I want to do a background scrolling effect for my game.
I can do 2 things:
-
place the background in the scene and a copy of the same background next it, and move them creating the scrolling effect. when the first one leaves the left side of the camera, it appears next to the copy at the far right of the camera. And this goes on and on.
-
Or I can use the SetTextureOffset with a certain offset speed and thats all.
I would like to reduce the work, but my concern is related to the speed of this solution … my image is kind of big.
Somebody knows if this is a viable option?
thanks in advance.
SetTextureOffset is plenty fast. The two copy method might give a tiny gap/blur where they meet (which might show up only certain places when they move.)
The graphics card keeps one copy of the texture in memory - it never scrolls or moves that around. Instead, it loves to look up the pixels, and will gladly look up partial areas, upside-down, wrapping around edges… . To it, every pixel lookup is the same. If you call it with pixelOffset 0.1 during a frame, then 0.11 the next, it won’t even notice you changed by 0.01. It didn’t “set up” the texture for a 0.1 lookup, or anything like that.
Note that offsets go from 0 to 1 over the texture and go backwards. So offset += Time.deltaTime*0.2f; will have the texture scroll R to L once/5 seconds.