Original Post
Hiya, I'm playing about trying to make a horizontal scrolling game. The background texture I have is quite a bit smaller than the screen. What I would like to do is have it so it is stretched to fit the screen and will scroll and repeat horizontally. I think I understand the principles but am having a bit of trouble implementing (I have been using the excellent site http://www.toymaker.info/Games/html/2d_scrolling.html ) The example in the link above is a vertical scroller and the texture stretches to fit the size of the screen. In my application I have got so far as loading the background texture and have it scroll correctly, it does not however stretch to fit the screen. Here's a comparision between the example program and mine:
The code I have for rendering the background is basically lifted off the website above, but I have been tinkering it so it scrolls horizontally rather than vertically so I'm a bit unsure why my program isn't working as per the example. Here is my background rendering code: Does anyone have any ideas? Thanks in advance
The code I have for rendering the background is basically lifted off the website above, but I have been tinkering it so it scrolls horizontally rather than vertically so I'm a bit unsure why my program isn't working as per the example. Here is my background rendering code:
//render background
RECT rct;
rct.top = 0;
rct.bottom = screenHeight;
D3DXVECTOR3 pos(0,0,0);
g_pDXSpriteBackground->Begin(0);
// left sprite
rct.left=textureWidth-offset;
rct.right=textureWidth;
g_pDXSpriteBackground->Draw(g_pBackTexture, &rct, NULL,&pos,0xFFFFFFFF);
//right sprite
rct.left=0;
rct.right=screenWidth - offset;
rct.top = 0;
rct.bottom = screenHeight;
pos.x=(float)offset;
g_pDXSpriteBackground->Draw(g_pBackTexture, &rct, NULL,&pos,0xFFFFFFFF);
// Done
g_pDXSpriteBackground->End();
//update offset
offset--;
if (offset< 0)
offset=textureWidth;
