Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Help with scrolling background  (Read 5031 times)

0 Members and 1 Guest are viewing this topic.

nisse pisse

  • Newbie
  • *
  • Posts: 9
    • View Profile
Help with scrolling background
« on: June 01, 2010, 09:29:32 pm »
Hello.
So i want a scrolling background. I get the background to scroll fine there is just one problem, there is a pixel gap.

http://data.fuskbugg.se/skalman01/-help.png



   
Code: [Select]
sf::Sprite bg1(background);
    sf::Sprite bg2(background);
    int bgheight;
    bgheight = 1904;
    bool bgActive1;
    bool bgActive2;
    int bgPosition1;
    int bgPosition2;
    bgPosition1 = 799;
    bg1.SetPosition(0,(bgPosition1-bgheight));
    bgActive1 = true;
    bgActive2 = false;


 // Start the game loop
     while (App.IsOpened())
     {
         if(App.GetFrameTime() < 0.0167){
             Sleep((0.0167-App.GetFrameTime())*1000);
         }
         // Process events
   

         if(bgActive1 == true){

             bgPosition1 = bgPosition1 + 1;
             bg1.SetPosition(0,(-bgheight+ bgPosition1));
         }
          if(bgActive2 == true ){

             bgPosition2 = bgPosition2 + 1;
             bg2.SetPosition(0,(-bgheight+ bgPosition2));
         }
          if((-bgheight+ bgPosition1) == 0 && bgActive1 == true){
                  bgActive2 = true;
                  bgPosition2 = 0;
                 bg2.SetPosition(0,-bgheight+ bgPosition1);

          }
     //     if((-bgheight)+ bgPosition1 == 800 && bgActive1 == true){
      //           bgActive1 = false;
       //      }
        if((-bgheight+ bgPosition2) == 0 && bgActive2 == true){
                  bgActive1 = true;
                  bgPosition1 = 0;
                 bg1.SetPosition(0,-bgheight+ bgPosition2);

          }
       //   if((-bgheight)+ bgPosition2 == 800 && bgActive2 == true){
        //         bgActive2 = false;
         //    }


/ Clear screen
         App.Clear();

       
            if(bgActive1 == true){
           App.Draw(bg1);
           }
           if(bgActive2 == true){
          App.Draw(bg2);
           }

           if(bgActive2 == true && bgActive1 == true){
               m++;
               if(m == 5){
               cout << endl << bgPosition1 << endl;
               cout << bgPosition2 << endl;

           }
           }

                   // Draw the string
        // App.Draw(Text);

         // Update the window
         App.Display();


     }

     return EXIT_SUCCESS;
 }


The picture is 1904 pixels in the y axis

I dont see where my thinking fails...

Skomakar'n

  • Newbie
  • *
  • Posts: 25
    • View Profile
Help with scrolling background
« Reply #1 on: June 16, 2010, 06:45:41 pm »
Somebody please answer... I have this problem too, and I see no reason for it not to work. Does the SFML view operate in a different thread? Maybe I should just make my own view system in the same thread... Or is there a way to wait for the thread before the screen is redrawn?

kitchen

  • Newbie
  • *
  • Posts: 14
    • View Profile
Help with scrolling background
« Reply #2 on: June 16, 2010, 09:15:08 pm »
This person was having the same problem as you. It seems that the solution is to sf::Image::SetSmooth(false) when loading it.

Skomakar'n

  • Newbie
  • *
  • Posts: 25
    • View Profile
Help with scrolling background
« Reply #3 on: June 17, 2010, 01:43:06 am »
Yeah, I found it myself. Was just about to post about it.
Hopefully OP will have use of your answer.

nisse pisse

  • Newbie
  • *
  • Posts: 9
    • View Profile
Help with scrolling background
« Reply #4 on: June 24, 2010, 10:11:18 am »
Yes it was that "set smooth" was set to true... one might wonder why that is the defualt setup when it works so bad O_o

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
Help with scrolling background
« Reply #5 on: June 25, 2010, 04:07:21 am »
Quote from: "nisse pisse"
Yes it was that "set smooth" was set to true... one might wonder why that is the defualt setup when it works so bad O_o


It's a bug that's been fixed with SFML 2.

Smooth is the default because smooth image filtering is considered standard in most modern apps--ie non 8-bit games.

 

anything