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

Author Topic: Sprite Source Rectangle Inaccurate?  (Read 2614 times)

0 Members and 1 Guest are viewing this topic.

Raycast

  • Newbie
  • *
  • Posts: 4
    • View Profile
Sprite Source Rectangle Inaccurate?
« on: March 07, 2013, 06:54:00 am »
I've been using SFML for a while, and I've only found basic workarounds for this, and I've never found out why this happens.

I wrote a basic tile engine setup that I've been using for several projects. It's what you'd expect, a vector of a vector of tiles with integer positions and sprites which are cut out of a spritesheet using the IntRect argument of the Sprite constructor.

My issue is that when the camera is at certain positions, the tiles' sourcerects cut into the next tile in the spritesheet. It's a little hard to explain, so I made a gif of it.



Spritesheet:


Hopefully that helps.

I'm thinking it might possibly have to do with how SFML's View class works. When I cast the view's position to an int, this issue doesn't happen at the cost of smooth camera movement.

Has anyone else had this problem? What can I do about this?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Sprite Source Rectangle Inaccurate?
« Reply #1 on: March 07, 2013, 07:56:32 am »
Quote
Has anyone else had this problem?
Yes, it's a known issue.

Quote
What can I do about this?
If you don't smooth your textures (i.e. didn't call texture.setSmooth(true)), then there's probably nothing you can do, except modifying the border pixels in your tileset so that the extra pixels become less visible.
Laurent Gomila - SFML developer

Raycast

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Sprite Source Rectangle Inaccurate?
« Reply #2 on: March 07, 2013, 08:16:52 am »
Ah, alright. Thanks. I'll see if I can work around it.

Raycast

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Sprite Source Rectangle Inaccurate?
« Reply #3 on: March 09, 2013, 01:47:58 am »
For anyone else who has had this problem, rounding the View's position to an int works well. If you have any camera interpolation or something, just make sure you round it after all transformations.

santiaboy

  • Full Member
  • ***
  • Posts: 118
    • View Profile
Re: Sprite Source Rectangle Inaccurate?
« Reply #4 on: March 16, 2013, 05:31:24 pm »
Phew, I'm not the only one. I was writing a short example but I couldn't replicate the problem, I guess it was because the lack of smooth camera movement.

However, if I round the View's position to an int, it works in the way that I don't have any "new lines". In my program it only happens at certain points (http://imgur.com/r2WDtvl) but the same lines apear over and over.

I did smooth the texture, and yet it happens.

Any ideas?