   2d infinitely scrolling background in all directions (C++ and Directx)
  This is my first attempt at posting a tut.First of all, i'd like to give credit to the guy that wrote this:http://www.toymaker.info/Games/html/2d_scrolling.html I don't know who you are but, thanks.Also, i'm not an expert programmer.This tut is to show how it could be done.Not how it should be done, so please go easy on the critisism.Although all is welcome.//DECLARATIONSLPD3DXSPRITE sprite_handler;//sprite interfaceLPDIRECT3DTEXTURE9 back_image;//texture interfaceD3DXVECTOR3 position (0,0,0);//3d vector, a 2d could also be usedRECT rct;//this will control the size of the imageint offsetx = 0;//X position of the rect on the screenint offsety = 0;//Y position of the rect on the screen#define SCREEN_WIDTH 1440//this should be your screen width#define SCREEN_HEIGHT 900//this should be your screen height//You'll need a seemless image the same size as your screen.//I used a picture of a starfield that I found on the internet//and resized it to fit my screen.//INITIALIZATION    back_image = LoadTexture("starfield.png", D3DCOLOR_XRGB(255,0,255));    if (back_image == NULL)   return 0;//function prototype... if you plan on defining//this function before it shows up in your code then this //is not necessarydrawbackground();//below is our functionvoid drawbackground (void)//voids indicate no return types or parameters{position.x = 0;//reset VECTOR3.x to 0position.y = 0;//reset VECTOR3.y to 0//the following is a bit hard to explain but//simply put, there are 4 instances of the image//3 of them are hiding until they are moved into the screen//by the offsets//top-rightrct.left=SCREEN_WIDTH-offsetx;rct.right=SCREEN_WIDTH;rct.top=SCREEN_HEIGHT-offsety;rct.bottom=SCREEN_HEIGHT;sprite_handler->Draw(back_image, &rct, NULL,&position,0xFFFFFFFF);//bottom-rightrct.left=SCREEN_WIDTH-offsetx;rct.right=SCREEN_WIDTH;rct.top=0;rct.bottom=SCREEN_HEIGHT-offsety;position.x = 0;position.y = offsety;sprite_handler->Draw(back_image, &rct, NULL,&position,0xFFFFFFFF);//top-leftrct.left=0;rct.right=SCREEN_WIDTH;rct.top=SCREEN_HEIGHT-offsety;rct.bottom=SCREEN_HEIGHT;position.x = offsetx;position.y = 0;sprite_handler->Draw(back_image, &rct, NULL,&position,0xFFFFFFFF);//bottom-leftrct.left=0;rct.right=SCREEN_WIDTH-offsetx;rct.top=0;rct.bottom=SCREEN_HEIGHT-offsety;position.x = offsetx;position.y = offsety;sprite_handler->Draw(back_image, &rct, NULL,&position,0xFFFFFFFF);// once the offsets reach there limits they are resetif (offsety > SCREEN_HEIGHT){offsety = 0;}if (offsety < 0){offsety = SCREEN_HEIGHT;}if (offsetx > SCREEN_WIDTH)   { offsetx = 0;}if (offsetx < 0){ offsetx = SCREEN_WIDTH;}//these increment the offsets, you could use something//else if you wantedif (Key_Down(DIK_UP)){   offsety++;}if (Key_Down(DIK_DOWN)){   offsety--;}if (Key_Down(DIK_RIGHT)){   offsetx++;}if (Key_Down(DIK_LEFT)){   offsetx--;}}// the only thing left to do is place thisdrawbackground ();//in your loopIf you have any questions feel free, i'll try to help in any way i can.One problem i did notice:If you use floating point numbers for your offsets, the truncation willcause the textures to move at different rates, and you will see it.[Edited by - moebious on May 9, 2009 3:23:22 AM]
  If you're using a DirectX interface, wouldn't it be easier to render a stationary textured quad with scrolling texture offsets?   