Page 1 of 1

Weird graphics glitch with .5 coordinates and scaling

Posted: Tue May 16, 2017 9:16 pm
by Jetmate
I'm currently working on a tile-based platformer where the levels are made up of a 50x50 grid of blocks the player can jump on. In order to provide the illusion of moving, I subtract the player's coordinates from the coordinates of every tile once each frame. I also scale the display by calling the love.graphics.scale function one time in the love.load function (with a factor of 3). However, I've noticed a weird phenomenon with this configuration - if the player has exactly (or very close to) a coordinate with a decimal of .5 (and thus all of the other tiles also have a .5 coordinate), a weird graphical glitch occurs. Here's an image without the glitch:

Image

Here's an image with the glitch:

Image

It seems like Love can't decide where to place a sprite, and so the pixels are in slightly different places. Does anyone have any idea on how to fix this, except for just not using decimal coordinates? Thank you.

Re: Weird graphics glitch with .5 coordinates and scaling

Posted: Wed May 17, 2017 3:10 am
by raidho36
This is just how GPUs draw textures: when texels don't exactly align with pixels, they get interpolated, i.e. smeared.

Re: Weird graphics glitch with .5 coordinates and scaling

Posted: Wed May 17, 2017 11:53 am
by Nixola
Use rounded coordinates, for drawing only (don't modify the original values).