Loading...
Logo
Processing Forum
Hello all,

I've run into a problem and can't think of a creative way around it. I am trying to shift the elements of a 2D array right or left depending on where a user places their cursor. I'm doing this to create the "illusion" of scrolling left and right (respectively). I've handled the shifting of elements to the left rather easily using a for loop, but I'm having trouble shifting to the right. 

It's a rather complicated problem to explain, but it has to do with the fact that I currently have to iterate forward through the array at all times, making shifting to the right difficult (since you usually just reverse the iteration direction). I've attached a link to download the code portion I'm talking about, just because it would take a rather verbose post to explain all the exceptions and reasoning behind the structure of the code.


The code in question is in the "scroll" tab and the method is called in the "draw" tab.

Any ideas on how to get this to work would be greatly appreciated. I've been at this for several hours and need a fresh perspective.

Thanks!

Replies(3)

Grrr just typed in a reply here and it disappeared!

The essence of it was:

Save current position, copy from current position in array to a parallel array (buffer), list or whatever.

Step through original array to start position + 1 and copy contents of buffer to it from there - net result contents shifted right.
This is exactly what I needed. I was too stuck mentally in trying to copy individual elements to a billion different variables to think about just copying the entire array!
You do it the same way you shift to the left, except you start at the maximum value, end at zero and thus, decrease the counter instead of increasing it.