SFML community forums
Help => Graphics => Topic started by: Jove on March 31, 2011, 03:45:31 pm
-
Apologies if I've missed the obvious.
I'm using SetSubRect to point at 64x64 images in a sheet and have noticed that when moving the sprites, I get part of the adjacent image 'creeping' in.
In this example, which is basically the tutorial, you can notice it as a white line at the edge of the sprite. Be patient when moving it around, sometimes it takes a little while to happen.
I suppose a workaround would be to leave a blank pixel on every edge, but I'd prefer to understand it better.
Thanks!
The test image is here:
(http://www.jestofevekites.com/markc/spritesheet.png)
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
sf::Image Image;
if (!Image.LoadFromFile("spritesheet.png"))
return EXIT_FAILURE;
Image.SetSmooth(false);
sf::Sprite Sprite(Image);
Sprite.SetColor(sf::Color(255, 255, 255, 255));
Sprite.SetPosition(200.f, 100.f);
Sprite.SetScale(.5, .5);
Sprite.SetSubRect(sf::IntRect(64, 64, 128, 128));
float xpos = 200;
float ypos = 100;
// Start game loop
while (App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
}
// Get elapsed time
float ElapsedTime = App.GetFrameTime();
// Move the sprite
if (App.GetInput().IsKeyDown(sf::Key::Left)) xpos -= 10 * ElapsedTime;
if (App.GetInput().IsKeyDown(sf::Key::Right)) xpos += 10 * ElapsedTime;
if (App.GetInput().IsKeyDown(sf::Key::Up)) ypos -= 10 * ElapsedTime;
if (App.GetInput().IsKeyDown(sf::Key::Down)) ypos += 10 * ElapsedTime;
Sprite.SetPosition(xpos, ypos);
App.Clear();
App.Draw(Sprite);
App.Display();
}
return EXIT_SUCCESS;
}
-
Are you using SFML 1.6 or 2? I had this issue (http://www.sfml-dev.org/forum/viewtopic.php?t=3920) with 1.6 and it was fixed by migrating to SFML 2 after I was told there was no way to fix it in 1.6
-
A Minecraft fan? Yay.
The third and fourth parameters in sf::IntRect are width and height, not right and bottom (at least in SFML2, which I am using). This is resulting in a large amount of whitespace to the bottom and left.
As for your problem, I am seeing it in SFML2. The only way I can think of to fix this is to ensure that the sprite is only drawn at integer coordinates.
-
I'm using SFML 1.6, so if changing to 2 would clear this up I don't need to worry about it too much for now?
I see it worked for you JAssange, but not for Oni.
@Oni - Width & Height make more sense, but in 1.6 they appear to be right/bottom.
It does help if drawn at integer coordinates, but if the screen is resized it can happen again.
So I guess switching to SFML 2 before my project gets too big would be a good idea?
Oni - Yes, I've put the hours in on Minecraft :wink:
-
So I guess switching to SFML 2 before my project gets too big would be a good idea?
Yes, especially since SFML1.x isn't maintained anymore.