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

Author Topic: Somtimes Black Line appears when drawing a sprite  (Read 2460 times)

0 Members and 3 Guests are viewing this topic.

P@u1

  • Jr. Member
  • **
  • Posts: 83
    • View Profile
Somtimes Black Line appears when drawing a sprite
« on: May 09, 2011, 06:05:42 pm »
Hi everyone,

I have a problem with drawing a simple sprite from an image.
Sometimes a black line at the right end of the image appears (its not regularly).
I created a minimal example to show this.
(I hope that you will see the same effect, a friend of mine already confirmed, that he has the same effects).
I uploaded the image I used here:
http://www.megaupload.com/?d=GPPOH5RP

Here is the source code:

Code: [Select]

#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>

int main()
{
sf::Image img;
img.LoadFromFile("marioandluigi.png");
img.SetSmooth(false);
sf::Sprite mario(img);
int x = 0;
mario.SetSubRect(sf::IntRect(1+17*x, 232, 1+17*x+16, 232+32));
mario.SetScale(5,5);
int xDir = 1;

sf::RenderWindow app(sf::VideoMode(800, 600, 32), "SFML Window");
while(app.IsOpened())
{
sf::Event event;
while (app.GetEvent(event))
{
if(event.Type == sf::Event::Closed)
{
app.Close();
}
}

app.Clear(sf::Color::Green);
app.Draw(mario);
if(mario.GetPosition().x > app.GetWidth() - mario.GetSize().x)
{
xDir = -1;
}
if(mario.GetPosition().x < 0)
{
xDir = 1;
}
mario.Move(app.GetFrameTime() * 100 * xDir, 0);
app.Display();
}
return 0;
}


Please tell me if you have any clue, why this line appears.

Father_Sloth

  • Newbie
  • *
  • Posts: 48
    • View Profile
Somtimes Black Line appears when drawing a sprite
« Reply #1 on: May 09, 2011, 06:49:47 pm »
Does this happen when moving, when not or what? If it's only when moving you could try limiting the Framerate or such.

 - Simon

P@u1

  • Jr. Member
  • **
  • Posts: 83
    • View Profile
Somtimes Black Line appears when drawing a sprite
« Reply #2 on: May 09, 2011, 07:06:39 pm »
It usually happens when moving but in my game (which is more than the source code i posted here) i also managed to stop moving in the right moment, so that the black line stays visible.
I just tried limiting the framerate, unfortunately it does not help.
Thanks for the suggeston anyway.

If some1 tries out my code with the picture, please make sure to run the program for atleast 30 seconds. Usually the effect appears much earlier, but it is not happening regularly so you might miss it if you dont test long enough.

Edit: I just recognized that the same or atleast a similar issue is mentioned here: http://www.sfml-dev.org/forum/viewtopic.php?t=4744

 

anything