Author Topic: Getting rid of gaps between adjacent sprites caused by floating point error?  (Read 4570 times)

Buey

  • Guest
I am creating a 2D tile based game by laying out GameObjects in a UITable, where each GameObject has a UISprite.  I am doing it this way rather than using a UITiledSprite because each Sprite's image is determined at run time, and each of these tiles can be individually altered by the player.  However, I am getting gaps between the tiles when the camera moves around.  I understand that this is caused by floating point error, and viewing the tiles at resolutions other than the initial one.  I would like to zoom in and out of the map though, so I need to be able to support this resolution change.

http://imgur.com/BgTgDqz

I've tried to find a way to get around this without much luck.  I've tried to overlap the tiles slightly but that ends up looking pretty bad.

Has anyone solved this sort of thing yet?  UITiledSprite seems to only use the native image resolution and doesn't suffer from this.
« Last Edit: March 17, 2013, 04:26:48 PM by Buey »

Buey

  • Guest
Actually, maybe it's just that UITable's padding is not specified in pixels?  Changing the padding from 0 to -1 or to 1 seems to shift it by much more than 1 pixel.  All my scales all the way up to the UIRoot are 1.

Buey

  • Guest
Setting padding to -0.2 seems to help, but that number seems pretty arbitrary.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
If I understand it right, it's caused when the position is not .0f, because of the way the texture filters with adjacent pixels. To test, try to set your atlas to use Point Filtering. Then it should go away. (but have other issues)

Optimally, each sprite should extend their color 1 pixel like an outline in the atlas, so that it filters into the same color as what's next to it, but I think that requires some reworking of the atlas maker.

Buey

  • Guest
Point filtering doesn't help.  As I understand it, the filtering option is also a cause of this in addition to scaling, and manifests itself even at the native resolution.  I think my issue is with the scaling, which also introduces floating point error.

Point filtering does work if I use the native resolution, but I want to be able to support zoom.  Using 0.2 as the offset seems to be okay right now.

I also did read about extending the outer pixels, but I don't think it could be done in the UIAtlas class itself.  I'm not using the atlas maker since I'm dynamically creating my atlas out of a single, pre-made image.

It might be possible to do it in a shader, but I know nothing about shader programming.
« Last Edit: March 17, 2013, 04:25:40 PM by Buey »