[Solved]love.graphics.translate

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
Dr.Tyler O.
Citizen
Posts: 58
Joined: Tue Jul 29, 2014 9:17 am
Location: United States

[Solved]love.graphics.translate

Post by Dr.Tyler O. »

I have been having this problem for a while now. Basically, if you attempt to translate graphics by anything except a whole number, printed text has some sort of graphical glitch and I can not find any information on this problem at all. Am I using love.graphics.translate incorrectly?

In the included love file, use the left and right arrow keys to translate the graphics on the x axis and look at what happens when x does not equal a whole number.
Translation Problems.love
(294 Bytes) Downloaded 75 times
Last edited by Dr.Tyler O. on Thu Mar 19, 2015 7:24 pm, edited 1 time in total.
Any topic I have ever posted that I felt did not require a .love file, although they were requested, never required one so I would appreciate if you did not ask me to supply one unless you think that I am ignorant for not doing so.
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: love.graphics.translate

Post by arampl »

Not sure if this is a good solution, but:

love.graphics.translate(-math.floor(x), 0)

will work.
User avatar
Dr.Tyler O.
Citizen
Posts: 58
Joined: Tue Jul 29, 2014 9:17 am
Location: United States

Re: love.graphics.translate

Post by Dr.Tyler O. »

arampl wrote:Not sure if this is a good solution, but:

love.graphics.translate(-math.floor(x), 0)
That method may stop the graphical glitching but it causes decimals to be completely ignored during graphics translation. The decimals are necessary for the current project I'm working on.
Any topic I have ever posted that I felt did not require a .love file, although they were requested, never required one so I would appreciate if you did not ask me to supply one unless you think that I am ignorant for not doing so.
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: love.graphics.translate

Post by arampl »

then:

love.graphics.push()
love.graphics.translate(-math.floor(x), 0)
love.graphics.print....
love.graphics.pop()
love.graphics.translate(-x, 0)

It seems that for text you should use whole numbers, for drawing lines - +/- 0.5 to get sharp image.
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: love.graphics.translate

Post by micha »

I saw in your file that you do this:

Code: Select all

love.graphics.translate(-x, 0)
love.graphics.print("X: "..x, x, 0)
In theory the translation of -x plus the printing at x should cancel out and the text should always appear at coordinates (0,0), but they don't. I was surprised by that and did some more tests. It seems that the love.graphics.print implicitly math.floors the coordinates before printing (remove the translate-line complete and run the game, the text only moves every second key-press). So the easiest solution is indeed to math.floor the translation coordinates as well.

May I ask why you need the decimals for translation in your project?
User avatar
DaedalusYoung
Party member
Posts: 407
Joined: Sun Jul 14, 2013 8:04 pm

Re: love.graphics.translate

Post by DaedalusYoung »

arampl wrote:It seems that for text you should use whole numbers, for drawing lines - +/- 0.5 to get sharp image.
That's because lines are 1 dimensional, while pixels are 2 dimensional. If you draw a line on integer coordinates, you are effectively drawing a line in between pixels. Your screen can not display this, so the line is blurred out between the pixel on one side and the pixel on the other side. If you add 0.5 to your coordinates, the line is drawn exactly in the middle of the pixel, so it doesn't need blurring.

Text does not consist of 1 dimensional lines (the fill anyway), so this does not apply. Additionally, as micha said, text is internally rounded to integer coordinates anyway, that would mean that printing it at the coordinate + 0.5 doesn't really change anything.
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: love.graphics.translate

Post by arampl »

That is a good explanation. Thank you!
User avatar
Dr.Tyler O.
Citizen
Posts: 58
Joined: Tue Jul 29, 2014 9:17 am
Location: United States

Re: love.graphics.translate

Post by Dr.Tyler O. »

I understand what you all are saying now, I couldn't understand last night at 2AM. Thank you for the help.
Any topic I have ever posted that I felt did not require a .love file, although they were requested, never required one so I would appreciate if you did not ask me to supply one unless you think that I am ignorant for not doing so.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 69 guests