Page 2 of 2

Re: Problem overriding love.graphics.print

Posted: Mon Mar 14, 2011 3:25 am
by BlackBulletIV
They made it like this:

Code: Select all

love.graphics.print = function (...)
    if not love.graphics.getFont() then
        love.graphics.setFont(12)
    end
    love.graphics.print1(...)
    love.graphics.print = love.graphics.print1
end
So that the first time print is called, it will create a default font to be used to actually output the text (if none has been set already of course).

Re: Problem overriding love.graphics.print

Posted: Mon Mar 14, 2011 10:06 am
by miko
Simtex wrote:This scales properly:

Code: Select all

love.graphics.oldPrint = love.graphics.print

function love.draw()
	love.graphics.scale(2, 2)
	love.graphics.print("Hardcore LOVE", 1, 1)
end

function love.graphics.print(text, x, y)
	love.graphics.oldPrint(text, x, y)
end
This doesn't (only the position of love.graphics.scale has changed):

Code: Select all

love.graphics.oldPrint = love.graphics.print

function love.draw()
	love.graphics.print("Hardcore LOVE", 1, 1)
end

function love.graphics.print(text, x, y)
	love.graphics.scale(2, 2)
	love.graphics.oldPrint(text, x, y)
end
Why?
The love.graphics.print gets reset for every loop iteration for some reason (unknown to me).
You can verify this by:

Code: Select all

function love.draw()
	print(love.graphics.print)
	love.graphics.print("Hardcore LOVE", 1, 1)
end
And that is the reason to use your own function, rather than redefining the original one.

Btw, in your own function, if you do scale(2,2) before oldPrint, then you should reverse it by scale(0.5, 0.5) after it. If not, every time you call print(), it would doble the scale.