Weird graphics glitch with .5 coordinates and scaling

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Jetmate
Prole
Posts: 12
Joined: Sun May 07, 2017 5:48 pm

Weird graphics glitch with .5 coordinates and scaling

Post 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.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Weird graphics glitch with .5 coordinates and scaling

Post by raidho36 »

This is just how GPUs draw textures: when texels don't exactly align with pixels, they get interpolated, i.e. smeared.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Weird graphics glitch with .5 coordinates and scaling

Post by Nixola »

Use rounded coordinates, for drawing only (don't modify the original values).
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Post Reply

Who is online

Users browsing this forum: pgimeno and 1 guest