SFML community forums
Help => Graphics => Topic started by: jd80127 on April 09, 2010, 12:52:25 am
-
Hi everyone. Thanks for this great site!
Anyways I am having a problem where black lines are drawn around my tiles. Here's an example with a white 64x64 tile:
(http://i984.photobucket.com/albums/ae326/jd80127/example1.jpg)
Here's the relevant segments of my code:
float loopVarX = 0;
float loopVarY = 0;
int forX, forY;
// Create the main window
sf::RenderWindow App(sf::VideoMode(1600, 1200), "MY GAME");
// SET 2 dimensional array of sprites all to the grass image
Sprite Sprite1[25][18];
for ( int a = 0; a<25; a++)
for (int b = 0; b<18 ; b++)
{
Sprite1[a][b].SetImage(CammyCreature.Grass);
}
// Draw the grass
for (forX = 0; forX <25; forX++) // DRAW 25 tiles horizontally
{
for (forY = 0; forY <18; forY++) // DRAW 18 tiles vertically
{
App.Draw(Sprite1[forX][forY]); // Draws the grass at the location specified by the variables
loopVarY = (forY * 64); // Configures the Y Coordinate to be images new location
Sprite1[forX][forY].SetY(loopVarY); // Sets the next Y Coordinate location of the next image to be drawn
Sprite1[forX][forY].SetX(loopVarX); // Sets the next Y Coordinate location of the next image to be drawn
}
loopVarX = (forX * 64);
}
Anyone have any ideas? I just upgraded from 1.5 to 1.6. I could be wrong but I thought that it was working with 1.5. I only noticed this with the upgrade to 1.6. Though its definitely possible that it could have been there the whole time. Could this be the 1.6 bug that other people are having problems with?
I could definitely post the whole program (123 lines of code) if you guys think that would help.
Thanks so much
-
Are you setting SetSmooth(false) on the image before loading it into the sprite? I've been using 1.6 for the tile engine I've been working on and it works fine unless I forget to set that.
-
Just check that your tiles origin and center are in round coordinates. If the problem persist, try disabling the smoothing like Breakman said before.
-
Thanks guys, very helpful forum.
SetSmooth(false) did the trick.
-
Thanks...had the same problem and it was driving me nuts :-)
-
It does work, but you probably have another problem.
-
And can you post a screenshot of what you get in your SFML application?
-
Well hopefully Laurent knows what's wrong.
I can't really help unless you tell me which SFMLv you are using and post the full code.
-
Well after taking a glance it looks like your position is off since there is 0,0 start position yet your multiplying it times 32 so it's creating a space.
If that doesn't solve it you can test your tiles to see if there is a hole by setting your clear color to red:
Engine.Screen.Clear(sf::Color(255,0,0));
UPDATE:I had some free time to test your code with tTile.Sprite.SetPosition( x * 31, y * 31 ); and I was right it works now.
-
The calculations for the tile positions are correct. I tested it with a 32x32 image of one of my tiles, and it works fine. But I hate having every tile in its own image, it's annoying to code with.
If I put the SubRect to (0, 0, 32, 32), it'll look fine for a while, but when you start moving, parts of the tiles below and to the right of the topleft tile in the tileset image show up
Well it's hard to tell. On the demo you sent me it's fixed
-
I did this to test and it worked seamlessly:
for (float x = 0; x < get_width+1; x++){
for (float y = 0; y < get_height+1; y++){
tTile.zSprite.SetPosition(x * 256, y * 128);
tTile.zSprite.SetImage ( Engine.TileSet );
tTile.zSprite.SetSubRect ( IntRect ( 0, 0, 256, 128 ) ) ;
-
But your SubRect there is just grabbing the entire image file, defeating the whole purpose.
That's just to test it. You can't see well with the brick because both sides have the same color. If you make it 32x32 it should work.
If you don't think it works try 64x64, take a screenshot and drop the source image on it photoshop it lines up correctly.
-
So, I suppose you corrected this:
tTile.Sprite.SetSubRect ( IntRect ( 0, 0, 31, 31 ) ) ;
to this
tTile.Sprite.SetSubRect ( IntRect ( 0, 0, 32, 32 ) ) ;
I tested with the code you initially posted, with the correct rect, and it worked fine. What's wrong now?
-
Yes,
It's a well known "bug". In order to have pixel art tiles you have to use Smooth to false, but when moving them around the screen they are using floating numbers thus, something is wrong with the drawing. Laurent knows that issue but "it's not a bug" as far as I know, it's just a tricky unsolvable problem...
-
Whatever the case I recommend using sfml2 if you can because it changes the rect code and fixes the smooth problem as well as other things.