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

Author Topic: [SOLVED] Problem displaying sprite  (Read 1802 times)

0 Members and 1 Guest are viewing this topic.

DMaxter

  • Newbie
  • *
  • Posts: 4
    • View Profile
[SOLVED] Problem displaying sprite
« on: February 04, 2020, 07:02:38 pm »
I'm developing a game with SFML, it is all fine, but the sprites are buggy (some of them).
I noticed that some sprites appear to be wrapping, even though they are the exact same size of the image (I printed the height and width of local bounds to check)

So this is how it should display the image: https://imgur.com/qjfTZyr
And this is how it is displayed: https://imgur.com/8QV9elL

I used basic options: loaded texture, set Sprite texture, set origin and position and then displayed

Is it some kind of bug or am I doing things the wrong way?
« Last Edit: February 06, 2020, 08:18:11 pm by DMaxter »

Fx8qkaoy

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: Problem displaying sprite
« Reply #1 on: February 06, 2020, 10:05:33 am »
"Talk is cheap. Show me the code"
« Last Edit: February 06, 2020, 01:11:48 pm by eXpl0it3r »

DMaxter

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Problem displaying sprite
« Reply #2 on: February 06, 2020, 04:02:25 pm »
Ask and you shall receive  ;)

This is where the texture is loaded, those are just strings, and this function executes `loadFromFile` on the texture and saves a reference to it in an hashtable.
Code: [Select]
assets.loadTexture(GM_GRID_MINI, GRID_MINI);
This is where the texture is set to a Sprite (this->grid is a sf::Sprite, and assets is the hashtable)
Code: [Select]
this->grid.setTexture(this->data->assets.getTexture(GM_GRID_MINI));
this->grid.setOrigin(halfWidth, halfHeight); // Half the height and width of the sprite
this->grid.setPosition(x, y); // This is simplified, it is not just x and y, but it works fine

And this is where it is displayed:
Code: [Select]
this->data->window.clear(//COLOR);
this->data->window.draw(this->grid);
this->data->window.display()

I don't know what am I doing wrong

Fx8qkaoy

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: Problem displaying sprite
« Reply #3 on: February 06, 2020, 05:17:02 pm »
Ask and you shall receive  ;)

This is where the texture is loaded, those are just strings, and this function executes `loadFromFile` on the texture and saves a reference to it in an hashtable.
Code: [Select]
assets.loadTexture(GM_GRID_MINI, GRID_MINI);
This is where the texture is set to a Sprite (this->grid is a sf::Sprite, and assets is the hashtable)
Code: [Select]
this->grid.setTexture(this->data->assets.getTexture(GM_GRID_MINI));
this->grid.setOrigin(halfWidth, halfHeight); // Half the height and width of the sprite
this->grid.setPosition(x, y); // This is simplified, it is not just x and y, but it works fine

And this is where it is displayed:
Code: [Select]
this->data->window.clear(//COLOR);
this->data->window.draw(this->grid);
this->data->window.display()

I don't know what am I doing wrong

Look into the documentation. Idk if u ever worked with metal OpenGL, but u can load a texture with different modes. Those are available in SFML too under a way or another, so on Texture u have things such as setSmooth(). Try all of those

DMaxter

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Problem displaying sprite
« Reply #4 on: February 06, 2020, 05:34:26 pm »
I'll try thati, but it is weird, because it only happens with some textures, maybe its because of the DPI... But when using an image viewer it doesn't happen, but I'll definitely try that

Fx8qkaoy

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: Problem displaying sprite
« Reply #5 on: February 06, 2020, 08:00:52 pm »
I'll try thati, but it is weird, because it only happens with some textures, maybe its because of the DPI... But when using an image viewer it doesn't happen, but I'll definitely try that

U have to pay attention to what image viewer to use cause the ones that are more for daily users rather than devs apply antialiasing (probably matters just if work with low resolutions). With the bare eye I can some effects applied on the first one (in case u're sure they are the same file with same res)

DMaxter

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Problem displaying sprite
« Reply #6 on: February 06, 2020, 08:17:25 pm »
I made the image myself, using Inkscape, I also opened it in GIMP and it looks nice. So, it has to be something in my program. They are the same file with same resolution (67px X 67px) that I can ensure you. Using smooth helped a lot, thank you very much for your help ;)