A scroller is quite simple a "virtual viewport" that pushes new tiles/objects in from direction you are scrolling.
Simple example to see this, is to build a simple 1 line marquee(textscroller).
Lets for example purpose say we have a line with 20 characters/letters/chars.
We place them in an string/array like:
String viewport = "....................";
String text = "Hello World (how original!)";
now if we print this, we will only see the "dots".
Console.WriteLine(viewport);
Now to scroll it, we need to make the dots go to the left. So we can read the text comming in.
For this to happend, we remove the first letter from left and adds the next to be shown from the right.
so we say:
viewport = viewport.Substring(2);
to take the 2nd letter and forward which equals rest of viewports current content.
Now the viewport is 1 char/letter to narrow, so we need to add the next char from the scroller. Therefore we need a variable for controlling where we are in the scrolltext.
// place this outside your scroll loop
int scrollPos =0;
Now with this index, we can find the next character.
char next = text.substring(scrollPos,1);
Then add this to the viewport.
viewport += next;
And increment your position in the scrolltext.
scrollPos++;
Now we have scrolled the contents 1 char left.
Keep doing this over and over, and it will look like the "Hello World" is scrolling across your viewport.
Now imagine this trick in all directions. Instead of characters, you use your own "Tiles". Secondly, to make it go smooth, you also add a "pixel scroll" within your scroller or you just multiple your scrollpos for simplicity. Then when you need to figure out which tile to add next, then just divide your current scrollpos with tile-width, then you know if you need to move the viewport scroll contents in any direction.
if you need to scroll arrays (with tile/block data) you can do it with simple for-loops.
left scroll
for (int pos=0;pos<viewwidth;pos++)
{
tilemap[pos] = tilemap[pos+1];
}
tilemap[width] = newTile; // from maparray.
Phew
That was a long explanation. Do you understand my point here, or do you need further explanation?