double axis scrolling?

Started by
0 comments, last by Neen10do 21 years, 1 month ago
hey guys, i want my background to be able to scroll on both the x and the y axis. i got it to work on the x axis alone... with a repeating background. i want to be able to do this with the y axis at the same time (diagonal). but this is the problem. if i was just using horizontal scrolling, all i had to do was this image: ------------------- |_________________| |_1_____________2_| |_________________| |_________________| |------------------ scrolling: ------------------- |______|___________| |____2_|__1________| |______|___________| |______|___________| |------------------ this causes a soup can effect (if you know what i mean. but lets say the image was like this: ------------------- |_1_____________2_ |_________________ |_________________| |_3_____________4_| |------------------ so possible scrolling situation could look like this: ------------------- |_____|____________| |____4|3___________| |-----|------------| |____2|1___________| |------------------ this shows how the corners could meet in the middle of the screen. any ideas on how to do this? note:: the solid horizontal lines are just to keep the box from collapsing.... the dotted lines are the picture divisions. ---------------------- i code therefore i am. Aero DX - Coming to a bored Monitor near you! [edited by - Neen10do on March 6, 2003 10:17:25 PM]
----------------------i code therefore i am.Aero DX - Coming to a bored Monitor near you!
Advertisement
if the background is the size of the screen, blit it 4 times, and keep the 4 corners meeting place on the screen, like if you keep track of the background position by the coordinates of the bottom right background, just wrap the values if they go off the screen.
if(x > SCREEN_WIDTH) x = 0;if(y > SCREEN_HEIGHT) y = 0;if(x < 0) x = SCREEN_WIDTH;if(y < 0) y = SCREEN_HEIGHT;   


(it might work better if those are <= and >= signs, you'll have to try it)

then, when you blit the backgrounds

blit(..., x - BACK_WIDTH, y - BACK_HEIGHT, ...) //top left tileblit(..., x, y - BACK_HEIGHT, ...) //top right tileblit(..., x - BACK_WIDTH, y, ...) //bottom left tileblit(..., x, y, ...) //bottom right tile   


this only works if the backgrounds are the same or greater than the screen, you'll need 9 if the background is smaller than the screen.

edit: x, y are the coordinates of the top left corner of the bottom right background

[edited by - billybob on March 6, 2003 10:26:39 PM]

This topic is closed to new replies.

Advertisement