Jump to content
  • Advertisement
Sign in to follow this  
garyfletcher

Scrolling to the left problem - last hope (SOLVED)

This topic is 4896 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement
Correct me if I'm wrong, but it looks like the mScrollRight is only responsible for repeating the image when the edge is visible? If that is the case, why is it neccessary to have an mScrollRight and mScrollLeft function instead of just an mScroll function (literally just rename mScrollRight to mScroll)?

If you need the mScrollRight/Left functions you can just copy/paste the code from mScrollRight to mScrollLeft and it should work...or at least I can't see why it wouldn't.

Share this post


Link to post
Share on other sites
MrP

You're completley right...the mScrollRight() function will do right AND left scrolling...man, all that fustration for nothing...how stupid of me. Thanks for spoting that..:)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!