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

Author Topic: Draw seems to be not correct.(sprites)  (Read 9510 times)

0 Members and 1 Guest are viewing this topic.

mimipim

  • Newbie
  • *
  • Posts: 49
    • View Profile
Draw seems to be not correct.(sprites)
« on: February 13, 2011, 12:27:18 am »
Hi guys.

I have a little problem with drawing a sprites.

See the picture:


Every image size is 32x32px... and every one sprite is drawed on 32x32 block but there still have a little black line between them. (maybe 1px).

Here is the grass image if you want to test.

bastien

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • http://bastien-leonard.alwaysdata.net
Draw seems to be not correct.(sprites)
« Reply #1 on: February 13, 2011, 12:36:06 am »
Try with Image.SetSmooth(false)? Otherwise it's probably a bug in your code in my opinion.
Check out pysfml-cython, an up to date Python 2/3 binding for SFML 2: https://github.com/bastienleonard/pysfml-cython

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Draw seems to be not correct.(sprites)
« Reply #2 on: February 13, 2011, 12:57:43 am »
Your probably doing a common mistake. You start at 0,0 and the width and height of a tile is 32 and 32. Thus the first pixel is at position 0,0 and then we have 31 in each direction left, giving us that the next tile should be placed at 0,32 or 32,0 and not 0,33 or 33,0.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

mimipim

  • Newbie
  • *
  • Posts: 49
    • View Profile
Draw seems to be not correct.(sprites)
« Reply #3 on: February 13, 2011, 11:16:41 am »
Look how I'm generating the place of the sprites:
Code: [Select]
   for(unsigned int a=0; a<15; a++)
    {
        objs.push_back(new Object("images/grass.png", 0, 32*a, "Grass"));
        objs.push_back(new Object("images/grass.png", 32, 32*a, "Grass"));
        if(a<=6)
        {
            objs.push_back(new Object("images/sand.png", 64, 32*a, "Sand"));
            objs.push_back(new Object("images/sand.png", 96, 32*a, "Sand"));
        }
    }


So I think theres no problem with my source.

About SetSmooth function - I already try it, but there no change.

 :?

devlin

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Draw seems to be not correct.(sprites)
« Reply #4 on: February 13, 2011, 12:36:40 pm »
There's no black "in between" them.

In the screenshot you posted, the tiles (without the black border) are 31x31 pixels - even though the grass you linked is a 32x32 tile.

Edit: In fact, looking at the pixeldata of the grass tile and the tiles in the original screenshot - the sprites are looking scaled down to 31x31 pixels.

There's an off-by-one error somewhere.

mimipim

  • Newbie
  • *
  • Posts: 49
    • View Profile
Draw seems to be not correct.(sprites)
« Reply #5 on: February 13, 2011, 12:38:38 pm »
Quote from: "devlin"
There's no black "in between" them.

In the screenshot you posted, the tiles (without the black border) are 31x31 pixels - even though the grass you linked is a 32x32 tile.


Sorry, but I don't understand you very good.
Can you explain with code please.

devlin

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Draw seems to be not correct.(sprites)
« Reply #6 on: February 13, 2011, 12:39:29 pm »
Probably missed my little edit:

Looking at the pixeldata of the grass tile and the tiles in the original screenshot - the sprites are looking scaled down to 31x31 pixels. (easily checked in for instance photoshop)

There's an off-by-one error somewhere.

Edit: We'll have to see your loading and rendering code to help you any further.

devlin

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Draw seems to be not correct.(sprites)
« Reply #7 on: February 13, 2011, 12:41:48 pm »
To rephrase it a bit more clearly:

The sprites in the screenshot are indeed spaced 32 pixels apart. However, the actual sprite image is scaled down to a 31x31 pixel image before rendering.

We'll have to see you actual loading and drawing code to help you find where the error is.

mimipim

  • Newbie
  • *
  • Posts: 49
    • View Profile
Draw seems to be not correct.(sprites)
« Reply #8 on: February 13, 2011, 12:47:12 pm »
I'm not resizing(scale) the image - I'm not so stuped. :D

devlin

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Draw seems to be not correct.(sprites)
« Reply #9 on: February 13, 2011, 12:50:10 pm »
I never once called you stupid.

My statement still stands, without the actual code - there's little we can do to help. It's up to you whether you want that help or not. :)

mimipim

  • Newbie
  • *
  • Posts: 49
    • View Profile
Draw seems to be not correct.(sprites)
« Reply #10 on: February 13, 2011, 12:57:48 pm »
This is all the code that create objects. You can see second and third argument is X and Y position on the sprite.

Theres no more code to edit sprite or image.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Draw seems to be not correct.(sprites)
« Reply #11 on: February 13, 2011, 01:07:05 pm »
I think devlin want to see the sprite being created.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

mimipim

  • Newbie
  • *
  • Posts: 49
    • View Profile
Draw seems to be not correct.(sprites)
« Reply #12 on: February 13, 2011, 01:14:57 pm »
Okay I do just a simple creating without my class.

Take a look at this:

Code: [Select]

int main()
{
    // Create the main window
    sf::RenderWindow Game(sf::VideoMode(640, 480), "Tower Defence");

    sf::Image grass;
    if(!grass.LoadFromFile("images/grass.png"))
        return EXIT_FAILURE;
    sf::Sprite spr_grass(grass);
    sf::Sprite spr_grass2(grass);
    sf::Sprite spr_grass3(grass);
    sf::Sprite spr_grass4(grass);
    sf::Sprite spr_grass5(grass);
    sf::Sprite spr_grass6(grass);

    spr_grass.SetPosition(0,0);
    spr_grass2.SetPosition(0,32);
    spr_grass3.SetPosition(0,64);
    spr_grass4.SetPosition(32,0);
    spr_grass5.SetPosition(64,0);
    spr_grass6.SetPosition(32,32);

    Game.SetFramerateLimit(60);

    // Start the game loop
    while (Game.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (Game.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                Game.Close();
        }

        if(Game.GetInput().IsMouseButtonDown(sf::Mouse::Left))
        {
            std::cout<<"X: "<<Game.GetInput().GetMouseX()<<std::endl;
            std::cout<<"Y: "<<Game.GetInput().GetMouseY()<<std::endl;
        }

        // Clear screen
        Game.Clear(sf::Color(0,0,0));

        Game.Draw(spr_grass);
        Game.Draw(spr_grass2);
        Game.Draw(spr_grass3);
        Game.Draw(spr_grass4);
        Game.Draw(spr_grass5);
        Game.Draw(spr_grass6);

        // Update the window
        Game.Display();
    }

    return EXIT_SUCCESS;
}


Result:



Can anyone help with this please.

Breakman79

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Draw seems to be not correct.(sprites)
« Reply #13 on: February 13, 2011, 05:49:55 pm »
In the example code you posted, you're not disabling the bilinear filtering on the image which adds the 1 pixel black line around it.  This is definitely something you have to set on every image loaded for use as a tile map.

In your example just change your image loading code to this and try it again:

Code: [Select]
sf::Image grass;
if(!grass.LoadFromFile("images/grass.png"))
    return EXIT_FAILURE;
grass.SetSmooth(false);
sf::Sprite spr_grass(grass);
sf::Sprite spr_grass2(grass);
sf::Sprite spr_grass3(grass);
sf::Sprite spr_grass4(grass);
sf::Sprite spr_grass5(grass);
sf::Sprite spr_grass6(grass);

mimipim

  • Newbie
  • *
  • Posts: 49
    • View Profile
Draw seems to be not correct.(sprites)
« Reply #14 on: February 13, 2011, 05:59:27 pm »
Okay.

The solution is found. SetSmooth helps this time.
But when I SetSmooth on objects in my class theres no change and no errors.

I will try some 'hooks' and write if I can't beat it.

Thanks.

Edit: Thanks to all. I make a litle edition on my class and now it's work perfect. Really thanks.