I've been trying to get my bitmap to scroll left ALL day, almost 12 hours and I still can't do it.
I can get it to scoll right ok...but LEFT, oh no. This is my last hope.
I've got an image that is 3909 pixels wide...scrolling right I check the amount I've scroll (I increase the scroll width with each iteration of the game loop and that works fine...the code for that is at bottom of the post. Seeing as this works I thought I'd base the scrolling left function on teh same code...but I just can't get it to work.
mScrollWCnt increase or decrease by 10 depending if we are moving right (increase) or left (decrease). If it gets <= 0 then mImg->w (3909) is added to it. mScrWidth = 800.
The code is:
void SiSEScrollImg::mScrollLeft()
{
// Scroll left
std::cout << "mScrollWCnt " << mScrollWCnt << std::endl;
std::cout << "mImg->w " << mImg->w << std::endl;
std::cout << "mScrWidth " << mScrWidth << std::endl;
std::cout << "mImg->w-mScrWidth " << mImg->w-mScrWidth << std::endl;
std::cout << "mOffSet " << mOffSet << std::endl;
if (mImg->w-mScrollWCnt > mImg->w-mScrWidth)
{
/*
if (mDoOffSet)
{
mOffSet = (int)mScrollWCnt;
mDoOffSet = false;
}
std::cout << "Drawing 2 images" << std::endl;
std::cout << "x position " << (int)(mOffSet+((mImg->w-mScrollWCnt)-(mImg->w-mOffSet))) << std::endl;
*/
mDrawImg(mImg,
(int)(mXPos-mScrollWCnt),
mYPos,
mImg->w,
mImg->h);
/*
mDrawImg(mImg,
(int)(mOffSet+((mImg->w-mScrollWCnt)-(mImg->w-mOffSet))),
mYPos,
(int)(mImg->w-mScrollWCnt),
mImg->h,
(int)mScrollWCnt,
(int)mScrollHCnt); // destY
mDrawImg(mImg, // srcSurface
mXPos, // srcX
mYPos, // srcY
(int)(mImg->w-(mOffSet+((mImg->w-mScrollWCnt)-(mImg->w-mOffSet)))),
mImg->h,
(int)mScrollWCnt,
(int)mScrollHCnt); // destY
*/
}
else
{
std::cout << "Drawing 1 image" << std::endl;
mDrawImg(mImg, // srcSurface
mXPos, // srcX
mYPos, // srcY
mImg->w, // width
mImg->h, // height
(int)mScrollWCnt, // destX
(int)mScrollHCnt); // destY
/*
mDoOffSet = true;
*/
}
return;
Right scroll (THIS IS OKAY - it works)
void SiSEScrollImg::mScrollRight()
{
// Scroll right
if (mScrollWCnt > mImg->w-mScrWidth)
{
std::cout << "Drawing 2" << std::endl;
mDrawImg(mImg, // srcSurface
mXPos, // srcX
mYPos, // srcY
(int)(mImg->w-mScrollWCnt), // width
mImg->h, // height
(int)mScrollWCnt, // destX
(int)mScrollHCnt); // destY
mDrawImg(mImg, // srcSurface
(int)(mImg->w-mScrollWCnt-1), // srcX
mYPos, // srcY
(int)(mScrWidth-(mImg->w-mScrollWCnt)), // width
mImg->h); // height
}
else
{
std::cout << "Drawing 1" << std::endl;
mDrawImg(mImg, // srcSurface
mXPos, // srcX
mYPos, // srcY
mImg->w, // width
mImg->h, // height
(int)mScrollWCnt, // destX
0); // destY
}
return;
}
As you can see I've tried quite a lot of stuff. It seems to work initially but then the drawn pixels dissapear and the image starts afresh from teh left of the screen.
What am I doing. If you need more info please let me know. PLEASE HELP!!! Before I go completely bonkers.
[Edited by - garyfletcher on May 28, 2005 9:08:03 AM]