# Some kind of circular scrolling background

## Recommended Posts

Hi people! I'm working on my own LaserAge version and I would like to make an important improvement. It's not just to make it cooler but for a necessity. I need to be able to scroll the background in all directions. If the spaceship goes to the right, the background moves left, if the spaceship goes up, the background moves down, if the spaceship goes to the bottom-left, the background moves to the top-right. The problem I have is that, I know how to make it look like a loop, but only vertically or horizontally; but I do not know how to do both at the same time. I believe I need some circular background to do the trick but the implementation is missing. BTW, I'm using C#, XNA GSE 1.0. Thanks! PD: I used this as reference, but it only works vertically: http://msdn2.microsoft.com/en-us/library/bb203868.aspx

##### Share on other sites
I'm just speculating based on what you posted, but it sounds like you just need to compose your background of interlocking shapes (e.g. rectangles, triangles, or hexagons, but not circles). Of these, a rectangle will be easiest and probably makes the most sense.

The rest kind of depends on the circumstances. For example, if the background is a rectangular sprite that exactly fills the play area, you could render it nine times (in a 3x3 grid), offset appropriately to account for the ship's position.

##### Share on other sites
I'm not positive.... the only way i can think of to scroll is have your viewing window defined by width height... with a position somewhere xy(z) if you want to scroll change the view by changing the x and y of the viewing window...
I'm at work so I dont really have much time to explain.. If you still haven't got it when I get home i'll go into more detail.
-durfy

##### Share on other sites
I'm not exactly sure what you mean when you say "both at the same time." Do you want to know how to scroll diagonally? If so, just change your view_x and view_y variables at the same time.

For example, let's say you wanted to move the spaceship to the upper-right corner and scroll the screen at the same time. You could do this:

//THIS IS PSEUDO-CODEif (key_up && key_right){    //Move spaceship    spaceship_x += 1;    spaceship_y -= 1;    //Scroll    view_x += 1;    view_y -= 1;}

Or, if you wanted to scroll the screen in any arbitrary direction, you could do this:

double calcAngleMoveX(int angle) {    return (double) cos(angle * 3.14 / 180);}double calcAngleMoveY(int angle) {    return (double) sin(angle * 3.14 / 180);}void move_ship(){    spaceship_x += calcAngleMoveX(spaceship_angle);    spaceship_y += calcAngleMoveY(spaceship_angle);    //Scroll    view_x += calcAngleMoveX(spaceship_angle);    view_y += calcAngleMoveY(spaceship_angle);}

NOTE: I'm not sure if my second method would work, since I haven't tested it. In theory, it should work, but I'm not 100% sure.

##### Share on other sites
Wow! Thanks the three of you for answering so fast!

My problem now is not exactly 'how to move the background diagonally', with your examples I got the idea pretty fast.

Now it is 'how to move the background diagonally giving the illusion of a loop'.

That's certainly what I don't get. How to make the appearance of infinite in every direction (I don't know if its even possible).

Thanks again!

##### Share on other sites
There is a way to do that. In fact, a lot of the old arcade scrollers did this to make the levels seem larger than they really were. It's a method called wrapping. I don't know how it's done, so I can't come up with an example at the moment. If I find out how it's done, I'll let you know.

##### Share on other sites
Yeah! I searched for 'wrapping' and I found an article about that.

##### Share on other sites
No problem, any time!

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627638
• Total Posts
2978327

• 10
• 12
• 22
• 13
• 34