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.
[Solved]love.graphics.translate
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Dr.Tyler O.
- Citizen
- Posts: 58
- Joined: Tue Jul 29, 2014 9:17 am
- Location: United States
[Solved]love.graphics.translate
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.
Re: love.graphics.translate
Not sure if this is a good solution, but:
love.graphics.translate(-math.floor(x), 0)
will work.
love.graphics.translate(-math.floor(x), 0)
will work.
- Dr.Tyler O.
- Citizen
- Posts: 58
- Joined: Tue Jul 29, 2014 9:17 am
- Location: United States
Re: love.graphics.translate
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.arampl wrote:Not sure if this is a good solution, but:
love.graphics.translate(-math.floor(x), 0)
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.
Re: love.graphics.translate
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.
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.
Re: love.graphics.translate
I saw in your file that you do this:
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?
Code: Select all
love.graphics.translate(-x, 0)
love.graphics.print("X: "..x, x, 0)
May I ask why you need the decimals for translation in your project?
Check out my blog on gamedev
- DaedalusYoung
- Party member
- Posts: 407
- Joined: Sun Jul 14, 2013 8:04 pm
Re: love.graphics.translate
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.arampl wrote:It seems that for text you should use whole numbers, for drawing lines - +/- 0.5 to get sharp image.
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.
Re: love.graphics.translate
That is a good explanation. Thank you!
- Dr.Tyler O.
- Citizen
- Posts: 58
- Joined: Tue Jul 29, 2014 9:17 am
- Location: United States
Re: love.graphics.translate
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.
Who is online
Users browsing this forum: Ahrefs [Bot] and 69 guests