From c6cfb28a353568126195dc4e94cb89d183fa5c8d Mon Sep 17 00:00:00 2001 From: Matt Mullins Date: Sat, 30 Oct 2010 21:11:46 -0500 Subject: [PATCH] Fixed the background code. --- Background.cpp | 90 ++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 41 deletions(-) diff --git a/Background.cpp b/Background.cpp index a90a4b8..7af7dd5 100644 --- a/Background.cpp +++ b/Background.cpp @@ -27,51 +27,59 @@ void Background::draw(){ /** \todo decide if wrapping should be a good default.*/ ///destination rectangle only position is used and describes where the output is drawn. SDL_Rect dest;/// mScreenSize.width)//move it to the left til it's 0 or less - x-=mScreenSize.width; - while(y > mScreenSize.height)//move it down til it's 0 or less - y-=mScreenSize.height; - while(x < 0)//move it to the right until it's in the drawable area - x+=mScreenSize.width; - while(y < 0)//move it up til it's - y+=mScreenSize.height; + while (x > mScreenSize.width) // move it to the left til it's on the screen + x -= mScreenSize.width; + while (y > mScreenSize.height) // move it up til it's on the screen + y -= mScreenSize.height; + while (x < 0) // move it to the right until it's in the drawable area + x += mScreenSize.width; + while (y < 0) // move it down til it's on the screen + y += mScreenSize.height; - if(wrapping){ - SDL_Rect extraX;/// 0 ){ - extraX.x = mScreenSize.width - x; - extraX.y = y; - extraX.w = x; - extraX.h = mScreenSize.height - y; - SDL_BlitSurface(mBackground, &extraX, mScreen, &dest); - } - /// \todo vertical wrapping - if(y > 0){ - extraX.x = x; - extraX.y = mScreenSize.height + y; - extraX.w = mScreenSize.width + x; - extraX.h = y; - SDL_BlitSurface(mBackground, &extraX, mScreen, &dest); - } - /* - if(x + _imageSize.width < mScreenSize.width){ - extraX.x = 0; - extraX.y = 0; - extraX.w = -x; - extraX.h = mScreenSize.height; - SDL_BlitSurface(mBackground, &extraX, mScreen, &dest); - }//*/ - } - dest.x = x; - dest.y = y; - SDL_BlitSurface(mBackground, &source, mScreen, &dest); + // Top-left portion of image + dest.x = x; + dest.y = y; + source.x = 0; + source.y = 0; + source.w = mScreenSize.width - x; + source.h = mScreenSize.height - y; + SDL_BlitSurface(mBackground, &source, mScreen, &dest); + + // Top-right portion of image + dest.x = 0; + dest.y = y; + source.x = mScreenSize.width - x; + source.y = 0; + source.w = x; + source.h = mScreenSize.height - y; + SDL_BlitSurface(mBackground, &source, mScreen, &dest); + // Lower-left portion of image + dest.x = 0; + dest.y = 0; + source.x = mScreenSize.width - x; + source.y = mScreenSize.height - y; + source.w = x; + source.h = y; + SDL_BlitSurface(mBackground, &source, mScreen, &dest); + + // Lower-right portion of image + dest.x = x; + dest.y = 0; + source.x = 0; + source.y = mScreenSize.height - y; + source.w = mScreenSize.width - x; + source.h = y; + SDL_BlitSurface(mBackground, &source, mScreen, &dest); + } else { + dest.x = mPos.X; + dest.y = mPos.Y; + // SDL_BlitSurface(mBackground, &source, mScreen, &dest); + } } SDL_Surface* Background::load(std::string filename){ -- 2.11.0